将.dll导入Qt [英] Importing .dll into Qt
问题描述
所以我把这个添加到我的.pro文件中:
win32 {
LIBS + = C:\lib\dependency.lib
LIBS + = C:\lib\ dependencies。 dll
}
然后(我不知道这是否是正确的语法或不)
#include< windows.h>
Q_DECL_IMPORT int WINAPI DoSomething();
btw .dll看起来像这样:
#include< windows.h>
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,
LPVOID lpReserved)
{
return TRUE;
}
externC
{
int WINAPI DoSomething(){return -1; }
};
获取错误:未解决的符号?
注意:我没有体验.NET的ez pz程序集architechture之外的.dll,绝对是一个n00b。
LIBS + =语法错误。尝试这样:
win32 {
LIBS + = -LC:/ lib / -ldependency
}
我也不知道在.pro文件中是否有驱动器号的绝对路径是一个好主意 - 我通常将依赖项保留在项目树中的某个位置并使用相对路径。
编辑:
我想您的dll中出现了某些错误,即符号导出不正确。我总是使用QtCreator提供的模板:
-
在dll项目中有mydll_global.h标题,代码如下:
#ifdef MYDLL_LIB
#define MYDLL_EXPORT Q_DECL_EXPORT
#else
#define MYDLL_EXPORT Q_DECL_IMPORT
#endif
-
Dll项目内有DEFINES + = MYDLL_LIB,它的pro文件。
-
导出的类(或仅选择的方法)和免费功能在头文件中标记为MYDLL_EXPORT,即
class MYDLL_EXPORT MyClass {
// ...
};
I want to bring a .dll dependency into my Qt project.
So I added this to my .pro file:
win32 {
LIBS += C:\lib\dependency.lib
LIBS += C:\lib\dependency.dll
}
And then (I don't know if this is the right syntax or not)
#include <windows.h>
Q_DECL_IMPORT int WINAPI DoSomething();
btw the .dll looks something like this:
#include <windows.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call,
LPVOID lpReserved)
{
return TRUE;
}
extern "C"
{
int WINAPI DoSomething() { return -1; }
};
Getting error: unresolved symbol?
Note: I'm not experienced with .dll's outside of .NET's ez pz assembly architechture, definitely a n00b.
Your "LIBS +=" syntax is wrong. Try this:
win32 {
LIBS += -LC:/lib/ -ldependency
}
I'm also not sure if having absolute paths with drive letter in your .pro file is a good idea - I usually keep the dependencies somewhere in the project tree and use relative path.
EDIT:
I suppose that something is wrong in your dll, i.e. the symbols are not exported correctly. I always use template provided by QtCreator:
Inside dll project there is mydll_global.h header with code like that:
#ifdef MYDLL_LIB #define MYDLL_EXPORT Q_DECL_EXPORT #else #define MYDLL_EXPORT Q_DECL_IMPORT #endif
Dll project has DEFINES += MYDLL_LIB inside it's pro file.
Exported class (or only selected methods) and free functions are marked with MYDLL_EXPORT inside header files, i.e.
class MYDLL_EXPORT MyClass { // ... };
这篇关于将.dll导入Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!