现在的位置: 首页 > 综合 > 正文

cl创建并调用dll

2018年02月16日 ⁄ 综合 ⁄ 共 1128字 ⁄ 字号 评论关闭

摆脱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

抱歉!评论已关闭.