在经历了一上午的头痛之后,我决定在我的第一个 Qt 项目中使用 Qt Creator 可能比 MSVC 更好(编译问题太多)。
我想知道如何通过 Qt Creator 添加外部工具所需的 .dll 和 .lib。我找到这篇文章 Adding external library into Qt Creator project这是有道理的。
我需要更多信息,例如...我是先链接 dll 还是 libs,将 dll 添加到 qmake 中的构建步骤的语法是什么(我假设它接近 win32:LIBS += path/to/Psapi.lib)
谢谢!
最佳答案
使用QtCreator/gcc编译外部库
如果您拥有您的库的源代码,这是一个 .pro 文件,用于从它们创建外部库(.dll 和 .a)或框架(在 Mac OS X 上):
TEMPLATE = lib
INCLUDEPATH = <your-include-paths>
HEADERS += <your-headers>
SOURCES += <your-sources>
TARGET = MyLib /* The name of your libary */
/* Win32: To generate a MyLib.dll and libMyLib.a (gcc) or MyLib.lib (MSVC) file */
win32 {
CONFIG += dll
}
/* Just in case you need to generate Mac Frameworks: */
macx {
CONFIG += shared lib_bundle
FRAMEWORK_HEADERS.version = Versions
FRAMEWORK_HEADERS.files += <your library headers>
/* Example:
FRAMEWORK_HEADERS.files += /path/to/your/lib/MyLib.h
*/
FRAMEWORK_HEADERS.path = Headers
QMAKE_BUNDLE_DATA = FRAMEWORK_HEADERS
VERSION = 0.5.0 // a framework version you can define
}
将外部库添加到您的 QtCreator/gcc 项目
/* your project settings */
/* If you compile on windows */
win32 {
/* If you compile with QtCreator/gcc: */
win32-g++:LIBS += /path/to/your/libMyLib.a
/* IF you compile with MSVC: */
win32-msvc:LIBS += /path/to/your/libMyLib.lib
}
/* If compile on Mac and want to link against a framework */
macx {
LIBS+= -framework MyLib
QMAKE_FLAGS += -F/path/to/MyLib
}
请注意,要将外部库与 gcc
一起使用,您需要包含链接信息的 libMyLib.a 文件。 libMyLib.lib
由 MS Visual Studio 生成,gcc afaik 无法处理!
关于c++ - 在 Qt Creator 中使用外部库/DLL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3858399/