[英]CMake app dependency on Qt-based library
I'll describe how my CMake project is currently arranged. 我将描述我的CMake项目目前的安排方式。 It's early, so suggestions for a better arrangement are welcome.
还为时过早,因此欢迎您提出更好的安排建议。
App depends on Lib1 Lib1 depends on Lib2 Lib2 uses Qt App取决于Lib1 Lib1取决于Lib2 Lib2使用Qt
folder structure: 文件夹结构:
I have CMakeLists.txt at each level. 我在每个级别都有CMakeLists.txt。
In Lib1 I add_library (STATIC), then target_link_library with Lib2 which is also STATIC. 在Lib1中,我add_library(STATIC),然后在target_link_library中也使用STATIC的Lib2。
Lib2's CMakeLists.txt does the find_package calls for Qt5Widgets, Qt5Core, and Qt5Gui. Lib2的CMakeLists.txt对Qt5Widgets,Qt5Core和Qt5Gui进行find_package调用。
Finally, App's CMakeLists.txt does the add_executable followed by target_link_libraries for Lib1. 最后,App的CMakeLists.txt对Lib1执行add_executable,后跟target_link_libraries。
Everything compiles and links until I actually make a call in the App code to use a function in Lib2. 一切都会编译并链接,直到我实际在App代码中调用以使用Lib2中的函数。 Then I get a bunch of unresolved symbol linker errors pointing to functions from Lib2.
然后,我得到一堆未解决的符号链接器错误,这些错误指向Lib2中的函数。 It doesn't seem to matter if I make Lib2 an OBJECT library and change the linking in Lib1 accordingly.
如果将Lib2设置为对象库并相应地更改Lib1中的链接,似乎并不重要。 I've also tried linking App against both Lib1 and Lib2 with the same results.
我还尝试过针对Lib1和Lib2链接App的结果相同。
What am I doing wrong here? 我在这里做错了什么?
Find_packages simply populates the variable with the library locations. Find_packages只是使用库位置填充变量。
You need to target_link_libraries on Lib2 with Qt5Widgets, Qt5Core, and Qt5Gui so cmake can properly link them. 您需要使用Qt5Widgets,Qt5Core和Qt5Gui在Lib2上使用target_link_libraries,以便cmake可以正确链接它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.