CMake include_directories和add_subdirectory之间的区别? [英] CMake Difference between include_directories and add_subdirectory?

查看:324
本文介绍了CMake include_directories和add_subdirectory之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习CMake来构建C ++代码,并努力遵循以下概念.在我的根目录下,我有一些cpp文件和CMakeLists.txt,它们在gen-cpp目录中成功生成了节俭代码.我的根目录CMakeLists.txt包含:

I'm learning CMake for building C++ code, and struggling with the following concept. On my root level directory I have some cpp files and a CMakeLists.txt that succesfully generates some thrift code in a gen-cpp directory. My root level CMakeLists.txt contains :

include_directories("root路径"/gen-cpp).(以及相关的节俭自动生成和包含.

include_directories("path-to-root"/gen-cpp). (along with the relevant thrift auto-generating and includes.

一切都可以编译,但是对于引用gen-cpp目录中定义的类的未定义符号,我得到了运行时动态库链接错误.当我将目录中的文件移动到根级别时,它运行良好.我想念什么?(我还调整了根级别cpp目录中的#include,使其指向"root路径"/gen-cpp).

Everything compiles ok but I get run time dynamic library linked errors for undefined symbol referencing a class defined in the gen-cpp directory. When I move the files in the directory to the root level, it runs fine. what am I missing? (I had also adjusted the #include in the root level cpp directorie s to point to "path-to-root"/gen-cpp).

这是对使用include_directory的误解,我应该在其中使用add_subdirectory.如果是后者,gen-cpp中的代码是否需要自己的CMakeLists.txt?当该目录的内容为根级别时,为什么不需要此附加文件?

Is this a misunderstanding of using include_directory, where I should be using add_subdirectory. If the latter, would the code in gen-cpp needs its own CMakeLists.txt? Why is this additional file not needed, when the contents of said directory are root level?

推荐答案

include_directories()用于添加标头搜索路径( -I 标志)和 add_subdirectory()在这种情况下不会有任何区别.

The include_directories() is used for adding headers search paths (-I flag) and add_subdirectory() will make no difference in this case.

我想,您需要在 add_executable() add_library()调用中列出gen-cpp文件夹中的* .cpp文件,您希望这些符号在会.

I suppose, you need to list *.cpp files from gen-cpp folder in add_executable() or add_library() calls, in which you wish these symbols to be.

或者,您可以将所有节俭的源代码编译到库中,并将其与您的代码链接.

Alternatively, you can compile all thrift sources into the library and link it with your code.

这篇关于CMake include_directories和add_subdirectory之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆