gpt4 book ai didi

c++ - CMake 在 C++ 项目中包含目录和环境变量

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:12:44 27 4
gpt4 key购买 nike

CMake 上的第一个定时器。我目前正在尝试使用 CMake 创建一个 visual studio 2013 解决方案(项目)。

所以我面临两个问题。

第一个是我在我的根目录 cMakeLists.txt 中使用了 include_directories,但不是要包含在 VC++ Directories 选项卡下的目录,而是包含在 C/C++ -> General -> Additional include directories 下。

第二个问题是我使用环境变量来包含这些目录,但不是在附加包含目录中打印:$(myVar)/lib/inc,而是将其打印为完整路径(例如 C:/../lib/inc),最终用户当然不会拥有与我相同的路径。

提前感谢您的任何回复。

最佳答案

我会尽力回答您的问题,以帮助您更好地了解 CMake 的工作原理。

First one is that i use include_directories in my root cMakeLists.txt but instead of the directories to be included under the VC++ Directories tab they are included under C/C++ -> General -> Additional include directories .

这正是 CMake 生成 Visual Studio 项目的方式。我不知道有什么方法可以改变这一点。

The second problem is that i use an enviroment variable to include those directories , but instead of printing then in the Additional include directories as such : $(myVar)/lib/inc it prints it as a full path (e.g. C:/../lib/inc) and the end user won't have of course the same path as mine.

为了避免生成的项目中出现歧义,CMake 倾向于将所有路径解析为完全限定路径。这(除其他事项外)意味着 CMake 项目不可重定位。这意味着 CMake 生成的项目不会在生成后移动,也绝对不会发送给其他用户在其他计算机上使用。

这对您来说意味着:如果您使用 CMake,您的所有最终用户也必须安装和使用 CMake。如果这对您的最终用户来说不可能或不切实际,那么 CMake 不是这个特定项目的解决方案。

关于c++ - CMake 在 C++ 项目中包含目录和环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38314854/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com