C近拍 - 动态的#include
我试图找出如何建立使用GCC #include语句的变量字符串。
I'm trying to figure out how to build a variable string for the #include statement using GCC.
的想法是,我已经写了各模块的话,我想包括作为标题,动态生成的 C 来源,先前在构建过程中创建的。
The idea is that for each source module I have written, I want to include as a header, a dynamically generated C source, that was created earlier in the build process.
生成该文件是不是一个问题。包括它,不幸的是,
Generating this file is not an issue. Including it, unfortunately, is.
我至今是(identities.h):
What I have so far is (identities.h):
// identities.h
# define PASTER2(str) #str
# define PASTER(str) PASTER2(str ## .iden)
# define EVALUATOR(x) PASTER(x)
# define IDENTITIES_FILE EVALUATOR(__FILE__)
# include IDENTITIES_FILE
在理想情况下,这将被用于像这样(main.c中):
Ideally, this would be used like so (main.c):
//main.c
# include "identities.h"
int main() {return 0;}
这将在单次通过由preprocessor扩大汇编之前,得到
Which would be expanded in a single pass by the preprocessor before compilation to yield:
//main.c (preprocessed)
# include "main.c.iden"
int main() {return 0;}
间接的两级我使用(贴膜和EVALUATOR)是this帖子。
不幸的是,这是行不通的,我留下了错误:
Unfortunately, this is not working and I am left with the error:
obj/win32/dbg/main.o
In file included from main.c:1:0:
identities.h:42:1: error: #include expects "FILENAME" or <FILENAME>
我觉得问题是,包括语句丢失报价..任何想法?
I think the problem is that the include statement is missing quotes.. Any ideas?
怎么样从的升压preprocessor库。它是专门做给周围添加一个名字报价。
What about BOOST_PP_STRINGIZE from the Boost Preprocessor library . It is specifically made to add quotes around a name.