CMake应用程序依赖于基于Qt的库(CMake app dependency on Qt

编程入门 行业动态 更新时间:2024-10-09 11:21:30
CMake应用程序依赖于基于Qt的库(CMake app dependency on Qt-based library)

我将描述我的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 App

I 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.

更多推荐

本文发布于:2023-07-30 15:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   依赖于   CMake   dependency   app

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!