Qt - Qt调用VS生成的C静态库


1,生成dll和lib库

在vs2010中新建工程,在向导中选择DLL,如下图所示:

新建两个文件mydll.h和mydll.c

mydll.h代码如下:

 1 #ifndef MYDLL_H
 2 #define MYDLL_H
 3 #ifdef __cplusplus //
 4  extern "C"{
 5  #endif
 6  __declspec(dllexport) int myFun(int a,int b);
 7 
 8 #ifdef __cplusplus
 9  }
10  #endif
11 
12 #endif

mydll.c代码如下:

1 #include "mydll.h"
2 #include <stdio.h>
3 
4 int myFun(int a,int b)
5 {
6     printf("myFun is called");
7 
8     return a+b;
9 }

编译运行,在Debug目录下可看到下述文件:

2.在Qt中调用dll和lib库

新建Qt工程LibTest2,将mydll.h文件添加到当前工程中;将mydll.lib和mydll.dll文件复制到工程所在目录;

在LibTest2.pro右键导入外部库,参数选项如下图所示:

在mainwindow.cpp中包含“mydll.h”

在构造函数中添加下述代码:

   int test;
      test = myFun(33,33);

      qDebug()<<test;

编译运行,结果如下:

可以看到C静态库已被调用。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM