看网上的好多关于QT调用Dll的方法,大部分都是调用函数的,并没有调用C++类成员的情况,即使是有,比如说:
我就是按照这上面的教程一步步做的,可惜了都没成功~~~这里面都有一个最重要的步骤没有说清楚(可能怪我笨~~),路径问题!!!
所以这里自我做一下总结:
创建时选择C++ Library就可以了,然后选择Shared Library(共享库),其他默认OK。
创建好后文件如下(我这里工程名为:dll)
其中dll.pro代码为:
1
2
3
4
5
6
7
8
9
10
11
12
TARGET = dll
TEMPLATE = lib
DEFINES += DLL_LIBRARY
SOURCES += \
dll.cpp
HEADERS +=\
dll_global.h \
dll.h
unix {
target.path = /usr/lib
INSTALLS += target
}
dll_global.h代码为:
1
2
3
4
5
6
7
8
9
#ifndef DLL_GLOBAL_H
#define DLL_GLOBAL_H
#include
#if defined(DLL_LIBRARY)
# define DLLSHARED_EXPORT Q_DECL_EXPORT
#else
# define DLLSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // DLL_GLOBAL_H
dll.h代码为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef DLL_H
#define DLL_H
#include
#include "dll_global.h"
using namespace std;
class DLLSHARED_EXPORT Dll
{
public:
Dll();
~Dll();
void Print();
string GetStrAdd(string str1, string str2);
};
extern "C"{
DLLS