Cmake的未定义引用链接错误
我正在自定义通过 cmake 构建的 qgis 源代码。
它有一个包含许多子目录的源树(其中也包含子目录)。
整个源代码树分为多个模块,例如 core(具有 GIS 核心组件)、gui(负责 gui)、app(负责主应用程序(包含 main.cpp))和其他模块。
问题是我遇到了一个要求,我需要访问不同模块中的静态类成员。 准确地说,是 Gui 模块中 QgisApp 类的一些成员。
因此,将 qgisapp.h 正常包含在 gui 模块的 .cpp 之一中会给我提供对我想要访问的 mamber 的未定义引用。 后来我将 .h 和 .cpp 包含在位于 Gui 模块根目录中的 CMakeLists.txt 文件中,并再次运行 cmake 以便 Makefile 具有正确的包含内容。 但如果未定义的引用大量,这实际上会增加数量(也许是因为我添加到 CMakeLists.txt 中的 .h 和 .cpp 本身包含在应用程序模块自己的 CMakeLists.txt 中引用的其他 .h 和 .cpp)。
那么,我如何在其他模块中使用某个模块的类成员,而该模块是使用放置在其各自根目录中的不同 CMakeLists.txt 集构建的?
这个问题与 qgis 没有特别相关,但可以遇到任何与 qgis 类似的源树。所以它基本上是一个与 Cmake 相关的问题。
希望我能够澄清我的问题。
帮助将不胜感激。
谢谢。
I am customizing qgis source code that builds through cmake.
It has a source tree with many sub directories(with sub-directories withinin them aswell).
The whole source tree is divided into modules like core,that has GIS core components,gui that takes care of the gui,app,that takes care of the main app(containing main.cpp) and other modules aswell..
The problem is that i am stuck with a requirement where i need to access a static class member in a different module. to be precise some member of QgisApp class in Gui module.
So normal inclusion of the qgisapp.h in one of the gui module's .cpp gives me undefined reference to the mamber that i want to access..
later i included the .h and .cpp in the CMakeLists.txt file that resides within the Gui module's root directory,and ran cmake again so that the Makefiles have the proper includes..
but that actually increased the number if undefined references a great deal (maybe because the .h and .cpp that i added into CMakeLists.txt itself includes other .h and .cpp that have references in the app module's own CMakeLists.txt).
So how can i use a member of a class of some module in some other module that is getting built with different set of CMakeLists.txt placed in its respective root directory??
This question is not specifically related to qgis but can come across with any source tree that is similar to what qgis has..So its a Cmake related question basically..
Hope i'm able to clearify my problem.
Help will be appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
target_link_libraries
应该做你正在寻找的事情。 如果这不起作用,您可以尝试发布一些示例 CMake 代码吗?target_link_libraries
should do what you are looking for. If this doesn't work can you please try and post some example CMake code?