如何仅适用于#IFDEF的GCC预处理标头,而不是#include和#defines
我必须预处理标头,在此期间,我只想处理#ifdef的标题,#if已定义的部分,其他部分(例如宏扩展)和#include部分不应扩展或检查#include部分。如何得到这个?我需要将此输出文件传递给其他软件,例如CMOCK来创建模拟文件,然后将其用于编译。但是我面临的问题是,如果我使用GCC -E,它会生成一个文件,其中所有#CRUDE都会扩展,宏随#if定义而扩展。 任何帮助都将不胜感激
例如,
#include <stdint.h> //i don't want to pre-process this line
#if defined (__MACRO_A__) //i want to pre-process this line
void funcA(void);
#else
void funcB(void);
#endif
:我希望输出文件仅具有funcb原型。我尚未定义 macro_a ,因此,如果我只包含了funcb的预处理标题,但是所有#includes都在扩展,我不想要。
I have to preprocess a header, during this I want to only process the header for #ifdef, #if defined sections, other sections like Macro expansion and #include sections should not be expanded or checked. how to get this? I need to pass this output file to another software like cmock to create a mock file and then use it for compilation. but the problem I am facing is if I use gcc -E it generates a file where all #includes are expanded, Macros expanded along with #if defines.
any help would be appreciated
for example:
#include <stdint.h> //i don't want to pre-process this line
#if defined (__MACRO_A__) //i want to pre-process this line
void funcA(void);
#else
void funcB(void);
#endif
I want the output file to have only funcB prototype. I have not defined MACRO_A, so if I preprocess header only funcB is getting included, but all the #includes are getting expanded, which I don't want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,将它们从文件中删除。
上面的正则可能会更好。
So remove them from the file.
The regex above can possibly be better.