Qt 调用外部C动态库

来源:互联网 发布:基金模拟交易软件 编辑:程序博客网 时间:2024/05/18 00:05

先写一个测试程序:

test.h

#include<stdio.h>

test();

test.c

#include<stdio.h>

test()

{

printf("hello,1234");

}

做成动态库,gcc -O -fPIC -shared -o libtest.so test.h test.c

将libtest.so和test.h拷贝到QT的工程目录,在pro文件中添加:LIBS += ./libtest.so

在工程的头文件中添加test.h时要添加extern "C"

extern "C"

{

#include "test.h"

}

在构造函数中直接使用test();函数即可。



原创粉丝点击