gcc -E -dM 为我提供了预处理器定义,但我希望它能够编译

发布于 2024-11-15 23:47:55 字数 369 浏览 0 评论 0原文

我有一个很大的源目录,具有复杂的 Makefile 结构(很多包含等)。

我想获取当您运行

gcc -E -dM 时 gcc 将提供的预处理器定义。但是,我也希望构建源代码。当我检查 make/build 日志时,我想查看 make 运行的所有命令,以及传递给编译器和/或覆盖的源中所有文件的 #defines。

我不知道该怎么做。

例如,

如果有一个文件 foo.c 仅包含这一行

#define PI 3.14

运行 gcc -E -dM foo.c 会将所有预处理定义打印到 stdout,以及里面的定义foo.c。

但它无法编译。如何组合命令以使这两种情况发生?

I have a large source directory with a complicated Makefile structure (lots of includes etc.)

I would like to grab the preprocessor defines that gcc will provide when you run

gcc -E -dM. However, I also want the source to be built. And when I check the make/build log, I'd like to see all the commands that were run by make, and ALSO the #defines from all the files in the source that were passed to the compiler and/or overriden.

I'm not sure how to go about this.

For e.g

If had a file foo.c with just this one line

#define PI 3.14

Running gcc -E -dM foo.c will print out all the preprocessory defines to stdout, as well as the define inside foo.c.

But it does not compile. How do I combine commands such that both things happen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拿命拼未来 2024-11-22 23:47:55

您需要分两遍执行此操作,但您可能可以设置一个 makefile 规则来执行此操作,例如用于编译 C 代码:

%.o: %.c
    $(CC) $(CFLAGS) -dM -E 
lt; > 
lt;.dump  # dump all preprocessor symbols to .dump file
    $(CC) $(CFLAGS) -c 
lt; -o $@          # compile to .o as normal

或者,如果您想将构建和预处理分开,您可以有两个规则,例如

%.o: %.c
    $(CC) $(CFLAGS) -c 
lt; -o $@          # compile to .o as normal

%.dump: %.c
    $(CC) $(CFLAGS) -dM -E 
lt; > 
lt;.dump  # dump all preprocessor symbols to .dump file

您还需要一个fake target 以确保所有 .c 文件生成 .dump 文件。

You need to do this in two passes, but you can probably set up a makefile rule to do it, e.g. for compiling C code:

%.o: %.c
    $(CC) $(CFLAGS) -dM -E 
lt; > 
lt;.dump  # dump all preprocessor symbols to .dump file
    $(CC) $(CFLAGS) -c 
lt; -o $@          # compile to .o as normal

Alternatively if you want to separate the build and preprocessing you could have two rules, e.g.

%.o: %.c
    $(CC) $(CFLAGS) -c 
lt; -o $@          # compile to .o as normal

%.dump: %.c
    $(CC) $(CFLAGS) -dM -E 
lt; > 
lt;.dump  # dump all preprocessor symbols to .dump file

You would also need a fake target to ensure that all the .c files generate .dump files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文