1.创建一个DLL
在文件testDLL.h修改
#ifndef TESTDLL_H
#define TESTDLL_H
#include "TestDll_global.h"
class TESTDLL_EXPORT TestDll
{
public:
TestDll();
int add(int a, int b);
};
#endif // TESTDLL_H
testDLL.cpp
#include "testdll.h"
TestDll::TestDll()
{
}
int TestDll::add(int a, int b)
{
return a+b;
}
选择构建,生成
2.dll的调用
新建一个控制台程序
将testDLL.h以及testdll_dlobal.h拷贝到新建项目下
修改配置文件,添加
HEADERS += \
TestDll_global.h \
testdll.h
将生成的TestDll.dll复制到项目文件下
在.pro下配置lib所在路径
LIBS+=F:\Qt_workstation\testDLLok\TestDll.dll
修改main.cpp为
#include <QCoreApplication>
#include <testdll.h>
#include <TestDll_global.h>
#include <iostream>
using namespace std;
int main()
{
//QCoreApplication a(argc, argv);
//return a.exec();
TestDll bb;
int a = 10;
int b = 15;
int c = bb.add(a,b);
cout<<c<<endl;
}
运行