问题描述
我发现 #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 ++包括完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!