为preprocessor串联包含路径 [英] Preprocessor concatenation for include path

查看:111
本文介绍了为preprocessor串联包含路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组包括驻留在一个遥远的目录意味着包括他们需要一个长期的包括,如:

I have a set of includes that reside in a far off directory meaning that including them requires a long include, such as:

#include "../../Path/to/my/file.h"

在那里我有这些多就显得有点不方便,所以我想我或许可以使用#定义的目录路径,然后CONCAT,我需要的文件名,即

Where I have multiple of these it becomes a bit inconvenient so I am thinking I may be able to use a #define for the directory path and then concat the file name that I need, i.e.

#define DIR "../../Path/to/my/"
#define FILE1 "file.h"
#define FILE2 "anotherFile.h"

#include DIR FILE1 // should end up same as line in first example after pre-proc

但是,这并不工作...反正有到C pre-处理器适合这种运作中串联?

However this does not work... is there anyway to concatenate within the workings of the C pre-processor suitable for this?

推荐答案

对于包括像这样的文件,你不能自定义的搜索路径,但你可以告诉编译器到哪里寻找包含文件。对于很多编译 -I 选项,例如:

You can't customise the search path for include files like this, but you can tell the compiler where to look for include files. Many compilers -I option for that, e.g.:

gcc -c stuff.c -I/path/to/my/ -I/path/to/other/

如果,让您的编译命令太长,你应该写一个Makefile文件,或者,如果您是在Visual Studio或类似的IDE工作,自定义您的项目设置的搜索路径。

If that makes your compilation command too long, you should write a Makefile or, if you are working in Visual Studio or similar IDE, customise the search path in your project settings.

这篇关于为preprocessor串联包含路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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