问题描述
我在Mac上构建了一些Qt项目,目前我正在尝试获取在Windows上构建相同的代码。在这些项目中,有一个dll(称为LibraryA)导出一个由第二个DLL(称为LibraryB)链接到的类(称为ClassA)。
I have got a few Qt projects building on my Mac and I am currently trying to get the same code to build on Windows. In among these projects there is one dll (call it LibraryA) that exports a class (call it ClassA) that is linked to by a second dll (call it LibraryB).
我有以下代码根据所使用的编译器定义要使用的dll导出代码。
I have the following code that defines the dll export code to be used based on the compiler being used.
#ifdef _MSC_VER
#if defined(LIBRARY_A)
#define LIBRARY_A_EXPORT __declspec(dllexport)
#else
#define LIBRARY_A_EXPORT __declspec(dllimport)
#endif
#else
#define LIBRARY_A_EXPORT
#endif
然后将其合并到我的类定义中。
I then incorporate this into my class definitions.
class LIBRARY_A_EXPORT ClassA
但是,在Windows上,我在LibraryB中得到了无法解析的符号__declspec(dllimport)。
However, on Windows I get unresolved symbol __declspec(dllimport) in the LibraryB.
我做错了什么?
编辑我创建了几个独立的项目来尝试使此工作正常(称为LibraryA和LibraryB再次)。 LibraryA成功构建,并且在LibraryB项目中,我使用添加库对话框,选择外部库。这给了我以下仍然不起作用的.pro文件条目
EDIT I created a couple of standalone projects to try and get this working (called LibraryA and LibraryB again). LibraryA successfully builds and in the LibraryB project I used the "Add Library" dialog, selecting External Library. This gives me the following .pro file entries which is still not working
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../build-LibraryA-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug/release/ -lLibraryA
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../build-LibraryA-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug/debug/ -lLibraryA
INCLUDEPATH += $$PWD/../build-LibraryA-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug/debug
DEPENDPATH += $$PWD/../build-LibraryA-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug/debug
推荐答案
我看到一些可能的情况:
I see a few possible scenarios:
- 缺少LibraryA.dll(未构建)。可能不是这样。
- LibraryB无法找到LibraryA。确保在LibraryB'pro'文件中具有正确的库路径:
LIBS + = -L $$ PWD / Path_To_LibraryA_Dll / -lLibraryA
- Library一个项目未定义
LIBRARY_A
宏,并且LIBRARY_A_EXPORT
未定义为__ declspec(dllexport)
,在这种情况下,LibraryA不会导出任何内容供外部使用。确保在LibraryA专业文件中具有定义:DEFINES + = LIBRARY_A
- LibraryA.dll is missing (not built). Probably not the case.
- LibraryB is not able to find LibraryA. Make sure you have the proper library path in LibraryB 'pro' file:
LIBS += -L$$PWD/Path_To_LibraryA_Dll/ -lLibraryA
- LibraryA project doesn't have
LIBRARY_A
macro defined, and theLIBRARY_A_EXPORT
doesn't get defined as__declspec(dllexport)
, in which case, LibraryA won't export anything for external usage. Make sure you have the define in LibraryA 'pro' file:DEFINES += LIBRARY_A
这篇关于如何在Windows上使用Qt Creator导出并链接到dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!