我有 #include
文件结构如下:
#include <core/mod1/file1.hpp>
#include <core/mod1/file2.hpp>
#include <core/mod1/mod2/.../modN/fileN.hpp>
每个文件中都有这样的包含。例如,在文件 core/mod1/file1.hpp
中可能有 #include <core/mod3/file5.hpp>
.
这里core
是我的图书馆的名字。但我想用 core_new
而不是 core
在整个项目中,没有修改所有文件(实际上很多)。
我试图添加 #define core core_new
,希望它能替代我需要的东西:
#define core core_new
#include <core/mod1/file1.hpp>
#include <core/mod1/file2.hpp>
#include <core/mod1/mod2/.../modN/fileN.hpp>
但它并没有这样做:core/mod1/file1.hpp
被包含而不是 core_new/mod1/file1.hpp
.
有办法实现吗?
最佳答案
您想使用文件系统,而不是 C++ 编译器。创建一个新目录并将所有源文件复制/链接到那里。将编译器中的 -I
选项更改为使用这个新目录。当然,将新文件放在新的 core
目录中。这样您就不需要编辑单个源文件/头文件。
关于c++ - 在包含中使用定义的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24141827/