我将描述我的CMake项目目前是如何安排的。 这是早期的,所以欢迎提出更好安排的建议。
App依赖于Lib1 Lib1依赖于Lib2 Lib2使用Qt
文件夹结构:
顶层 LIB1 LIB2 应用我在每个级别都有CMakeLists.txt。
在Lib1中我添加了lib_library(STATIC),然后是带有Lib2的target_link_library,它也是STATIC。
Lib2的CMakeLists.txt为Qt5Widgets,Qt5Core和Qt5Gui执行find_package调用。
最后,App的CMakeLists.txt执行add_executable,然后执行Lib1的target_link_libraries。
一切都编译和链接,直到我实际在App代码中调用以使用Lib2中的函数。 然后我得到一堆未解决的符号链接器错误,指向Lib2中的函数。 如果我将Lib2设为OBJECT库并相应地更改Lib1中的链接似乎并不重要。 我也尝试将App与Lib1和Lib2连接起来,结果相同。
我在这做错了什么?
I'll describe how my CMake project is currently arranged. It's early, so suggestions for a better arrangement are welcome.
App depends on Lib1 Lib1 depends on Lib2 Lib2 uses Qt
folder structure:
top-level Lib1 Lib2 AppI have CMakeLists.txt at each level.
In Lib1 I add_library (STATIC), then target_link_library with Lib2 which is also STATIC.
Lib2's CMakeLists.txt does the find_package calls for Qt5Widgets, Qt5Core, and Qt5Gui.
Finally, App's CMakeLists.txt does the add_executable followed by target_link_libraries for Lib1.
Everything compiles and links until I actually make a call in the App code to use a function in Lib2. Then I get a bunch of unresolved symbol linker errors pointing to functions from Lib2. It doesn't seem to matter if I make Lib2 an OBJECT library and change the linking in Lib1 accordingly. I've also tried linking App against both Lib1 and Lib2 with the same results.
What am I doing wrong here?
最满意答案
Find_packages只是使用库位置填充变量。
您需要使用Qt5Widgets,Qt5Core和Qt5Gui在Lib2上使用target_link_libraries,以便cmake可以正确链接它们。
Find_packages simply populates the variable with the library locations.
You need to target_link_libraries on Lib2 with Qt5Widgets, Qt5Core, and Qt5Gui so cmake can properly link them.
更多推荐
发布评论