Qt pro文件中引用第三方库
在实际开发中如果你想要使用除了那些 Qt 项目中提供的第三方库,你就需要在你的项目文件中引用它们。下面以第三方加密库 CryptoPP 为例子,讲述如何在 Qt pro 文件中引用第三方库。
为了Qt项目文件在其他的机器上也能兼容,在 Windows 中可以添加环境变量:
变量名:cryptoppDir
变量值:F:\ThirdParty\cryptopp562
其中变量值为第三方库 CryptoPP 的所在位置。
打开项目文件(.pro文件),在文件的最下方添加如下代码(具体值根据实际情况修改):
win32-g++:CONFIG(release, debug|release): LIBS += -L$$(cryptoppDir)/libs/mingw/release -lcryptopp
else:win32-g++:CONFIG(debug, debug|release): LIBS += -L$$(cryptoppDir)/libs/mingw/debug -lcryptopp
else:win32:!win32-g++:CONFIG(release, debug|release): LIBS += -L$$(cryptoppDir)/libs/win32/release -lcryptopp
else:win32:!win32-g++:CONFIG(debug, debug|release): LIBS += -L$$(cryptoppDir)/libs/win32/debug -lcryptopp
win32: INCLUDEPATH += $$(cryptoppDir)
win32: DEPENDPATH += $$(cryptoppDir)
win32:!win32-g++:DEFINES += CRYPTOPP_DLL_ONLY
其中 “win32-g++” 代表 MinGW 编译器,如果是 Visual Studio 编译器可以为 “win32” 或 “win32-msvc2010”。“-L”代表第三方库所在的路径,“-l” 代表库名,扩展名可以省略。
也可以写成如下格式:
unix:LIBS += -L/usr/local/lib -lmath
win32:LIBS += c:/mylibs/math.lib
如果路径中包含“ ”(空格),只需使用引号包含:
win32:LIBS += "C:/mylibs/extra libs/extra.lib"
unix:LIBS += "-L/home/user/extra libs" -lextra
[…] Qt pro文件中引用第三方库 […]
[…] Qt pro文件中引用第三方库 […]