13

我只想获得预处理版本的file.cc. 我做到g++ -E file.cc了,得到:

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

我做错了什么?

4

2 回答 2

18

假设您的源文件包含一个简单的 main 函数:

$ 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为空时发生。请注意,“空”意味着文件仍然可以包含注释,或者#ifdef条件评估为假的块 - 由于预处理器将它们过滤掉,它们也不会出现在输出中。

于 2012-09-19T07:17:12.397 回答
8

如果您不想要线标记,请使用 -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. 
于 2012-09-19T07:20:50.560 回答