g++ 预处理器输出

16

我希望只获取预处理后的file.cc版本。我执行了g++ -E file.cc,得到:

# 1 "file.cc"
# 1 "<command-line>"
# 1 "file.cc"

我做错了什么?


1
改善你的帖子。包括你的源文件等内容。 - Kirill Kobelev
5
源文件必须为空吗? - trojanfoe
1
除非您说出您做了什么以及您期望发生什么,否则我们无法知道您做错了什么。 - tenfour
2个回答

20

假设你的源文件包含一个简单的主函数:

$ cat file.cc
int main() {
    return 0;
}

然后,使用你展示的命令,输出看起来像这样:

$ g++ -E file.cc
# 1 "file.cc"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "file.cc"

int main() {
    return 0;
}

问题中显示的输出是在file.cc为空时发生的。请注意,“空”意味着文件仍然可以包含注释或具有计算结果为false的#ifdef块 - 因为预处理器会过滤它们,所以它们也不会出现在输出中。


9
如果您不想要行标记,请使用-P选项:
-P
    Inhibit generation of linemarkers in the output from the preprocessor. This might
    be useful when running the preprocessor on something that is not C code, and will
    be sent to a program which might be confused by the linemarkers. 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接