C ++包括完整路径

编程入门 行业动态 更新时间:2024-10-24 02:29:07
本文介绍了C ++包括完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我发现 #include../ app / thing.h非常难看,我希望能够从我项目的主根导入,比如这个:

I find #include "../app/thing.h" very ugly and I would like to be able to import from the main root of my project, like this:

#include< project / app / submodule / thing.h>

(我知道<>通常用于外部,但我觉得它更干净)

(I know <> is generally used for external but I find it very cleaner)

我怎么能在任何地方都这样做在我的项目中?

How can I do that, from anywhere in my project?

推荐答案

您只需确保构建过程设置一个选项以指定搜索的起始点。

You simply need to ensure that your build process sets an option to specify the starting point of the search.

例如,如果您的标题位于:

For example, if your header is in:

/work/username/src/project/app/submodule/thing.h

然后你需要包括(假设符合POSIX的编译器; AFAICR,甚至MSVC使用 / I 作为 -I 的类似物:

then you need to include (assuming a POSIX-compliant compiler; AFAICR, even MSVC uses /I as the analogue of -I):

-I/work/username/src

作为编译器选项之一。您可以从项目的任何位置使用该路径,因为它是绝对的。你只需要一个定义的方式让你的构建系统知道设置应该是什么,所以当它被移动到 / home / someone / src / 时,你只有一个设置改变。

as one of the compiler options. You can use that path from anywhere in your project since it is absolute. You just need a defined way for your build system to know what the setting should be, so that when it is moved to /home/someone/src/, you have only one setting to change.

更多推荐

C ++包括完整路径

本文发布于:2023-11-30 05:33:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648892.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   完整

发布评论

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

>www.elefans.com

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