摆脱IDE,废话不说,贴代码
先写两个源文件
//
//testdll.cpp
_declspec(dllexport) double add(double da ,double db)
{
return da+db;
}
_declspec(dllexport) double subtract(double da , double db)
{
return da-db;
}
//
//main.cpp
#include <iostream.h>
extern double add(double da ,double db);
extern double subtract(double da , double db);
void main()
{
cout<<"testdll"<<endl;
cout<<"3.2+6.5="<<add(3.2,6.5)<<endl; //9.7
cout<<"6.8-2.6="<<subtract(6.8,2.6)<<endl; //4.2
}
//
打开命令提示符,输入以下命令
cl /c testdll.cpp //生成testdll.obj
link /dll testdll.obj //生成testdll.lib testdll.exp testdll.dll
cl /c main.cpp //生成main.obj
link main.obj testdll.lib //生成main.exe
执行main.exe
结果:
testdll
3.2+6.5=9.7
6.8-2.6=4.2