问题描述
我正在为qt应用程序准备cmake构建。我在使用以下结构..
I am preparing cmake build for qt application. where I am using following structure ..
libMyApp
使用
libMyAppwhich uses
SET(QT5_MODULES Widgets PrintSupport Network XmlPatterns)
FIND_PACKAGE(Qt5 REQUIRED COMPONENTS ${QT5_MODULES})
和
TARGET_LINK_LIBRARIES(
${TARGET_NAME}
Qt5::Widgets
Qt5::PrintSupport
Qt5::Network
Qt5::XmlPatterns
)
libMyApp构建成功并生成libMyApp.a(静态库)
libMyApp build successfully and generated libMyApp.a (static library)
现在我正在我的应用程序MyApp
中使用该库,该库使用
Now I am using this library in my application MyAppwhich uses
SET(QT5_MODULES Widgets PrintSupport XmlPatterns)
FIND_PACKAGE(Qt5 REQUIRED COMPONENTS ${QT5_MODULES})
TARGET_LINK_LIBRARIES(
${TARGET_NAME}
Qt5::Widgets
Qt5::PrintSupport
Qt5::XmlPatterns
${CODE_LIB_FILES}
)
$ {CODE_LIB_FILES}在列表中libMyApp.a的引导路径$ a $ b MyApp成功构建,最后显示链接错误
${CODE_LIB_FILES} is list holding path of libMyApp.aMyApp builds successfully and at last shows linking error
undefined reference to `QPrinter::QPrinter(QPrinter::PrinterMode)
xml也发生了同样的事情
Same thing happening with xml also
undefined reference to `QDomNode::isElement() const'
任何人都可以指出这里出了什么问题吗?
can anyone point out what is wrong here ?
或任何使用printsupport和xmlpatterns模块描述相同场景的示例程序
or any sample program depicting same scenario with printsupport and xmlpatterns module
推荐答案
函数 TARGET_LINK_LIBRARIES()
中的条目顺序很重要。最后要提到没有依赖关系的库,它们通常是一些标准库或外部库,在此示例中是Qt5库。
The order of the entries in the function TARGET_LINK_LIBRARIES()
is important. The libraries with no dependecies shall be mentioned last which are typically some standard libraries or external libraries, in this example the Qt5 Libs.
示例:
- 取决于应用程序
-
Lib_A
取决于Lib_B
和Lib_std
-
Lib_B
取决于在Lib_std
-
Lib_std
没有依赖项
- Application depends
Lib_A
depends onLib_B
andLib_std
Lib_B
depends onLib_std
Lib_std
has no dependencies
然后调用该函数:
TARGET_LINK_LIBRARIES(
${TARGET_NAME} # Name of the app
"Lib_A"
"Lib_B"
"Lib_std" # Last entries: Std Libs, external Libs, ...
)
在此应用程序中,我假设 $ {CODE_LIB_FILES} = libMyApp.a
与Qt5-Lib有一些依赖关系,因此可以将此项移至Qt5-Lib之上。
In this application I assumed that ${CODE_LIB_FILES}=libMyApp.a
has some dependencies to the Qt5-Libs so it would be plausible to move this entry above the Qt5-Libs.
SET(QT5_MODULES Widgets PrintSupport XmlPatterns)
FIND_PACKAGE(Qt5 REQUIRED COMPONENTS ${QT5_MODULES})
TARGET_LINK_LIBRARIES(
${TARGET_NAME}
${CODE_LIB_FILES} # <<< Moved this entry up
Qt5::Widgets
Qt5::PrintSupport
Qt5::XmlPatterns
)
这篇关于Cmake Qt5 |未定义对`QPrinter :: QPrinter(QPrinter :: PrinterMode)的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!