如何强制 make/GCC 显示命令?

发布于 2024-11-03 17:50:36 字数 1057 浏览 0 评论 0原文

我正在尝试调试编译问题,但我似乎无法让 GCC (或者可能是 make??) 向我显示它正在执行的实际编译器和链接器命令。

这是我看到的输出:

  CCLD   libvirt_parthelper
libvirt_parthelper-parthelper.o: In function `main':
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:102: undefined reference to `ped_device_get'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:116: undefined reference to `ped_disk_new'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:122: undefined reference to `ped_disk_next_partition'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:172: undefined reference to `ped_disk_next_partition'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:172: undefined reference to `ped_disk_next_partition'
collect2: ld returned 1 exit status
make[3]: *** [libvirt_parthelper] Error 1

我想要看到的应该与此类似:

$ make
gcc -Wall   -c -o main.o main.c
gcc -Wall   -c -o hello_fn.o hello_fn.c
gcc   main.o hello_fn.o   -o main

请注意此示例如何显示完整的 gcc 命令。上面的示例仅显示“CCLD libvirt_parthelper”之类的内容。我不知道如何控制这种行为。

I'm trying to debug a compilation problem, but I cannot seem to get GCC (or maybe it is make??) to show me the actual compiler and linker commands it is executing.

Here is the output I am seeing:

  CCLD   libvirt_parthelper
libvirt_parthelper-parthelper.o: In function `main':
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:102: undefined reference to `ped_device_get'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:116: undefined reference to `ped_disk_new'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:122: undefined reference to `ped_disk_next_partition'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:172: undefined reference to `ped_disk_next_partition'
/root/qemu-build/libvirt-0.9.0/src/storage/parthelper.c:172: undefined reference to `ped_disk_next_partition'
collect2: ld returned 1 exit status
make[3]: *** [libvirt_parthelper] Error 1

What I want to see should be similar to this:

$ make
gcc -Wall   -c -o main.o main.c
gcc -Wall   -c -o hello_fn.o hello_fn.c
gcc   main.o hello_fn.o   -o main

Notice how this example has the complete gcc command displayed. The above example merely shows things like "CCLD libvirt_parthelper". I'm not sure how to control this behavior.

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

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

发布评论

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

评论(8

习ぎ惯性依靠 2024-11-10 17:50:36

调用试运行

make -n

这将显示make正在尝试执行的操作。

To invoke a dry run:

make -n

This will show what make is attempting to do.

树深时见影 2024-11-10 17:50:36

构建系统独立方法

make SHELL='sh -x'

是另一种选择。示例 Makefile

a:
    @echo a

输出:

+ echo a
a

这为 make 设置特殊的 SHELL 变量,-x 告诉 sh 在执行之前打印扩展行。

相对于 -n 的一个优点是它实际上运行命令。我发现对于某些项目(例如 Linux 内核), -n 可能会比平常更早停止运行,可能是因为依赖性问题。

此方法的一个缺点是您必须确保将使用的 shell 是 sh,这是 Make 使用的默认 shell,因为它们是 POSIX,但可以使用 进行更改SHELL 使变量。

执行 sh -v 也很酷,但是 Dash 0.5.7 (Ubuntu 14.04 sh) 会忽略 -c 命令(这似乎是 make 使用它的方式),所以它不做任何事情。

make -p 您也会感兴趣,它打印设置变量的值。

CMake 生成的 Makefile 始终支持 VERBOSE=1

如:

mkdir build
cd build
cmake ..
make VERBOSE=1

专用问题:将 CMake 与 GNU Make 结合使用:如何查看确切的命令?

Build system independent method

make SHELL='sh -x'

is another option. Sample Makefile:

a:
    @echo a

Output:

+ echo a
a

This sets the special SHELL variable for make, and -x tells sh to print the expanded line before executing it.

One advantage over -n is that is actually runs the commands. I have found that for some projects (e.g. Linux kernel) that -n may stop running much earlier than usual probably because of dependency problems.

One downside of this method is that you have to ensure that the shell that will be used is sh, which is the default one used by Make as they are POSIX, but could be changed with the SHELL make variable.

Doing sh -v would be cool as well, but Dash 0.5.7 (Ubuntu 14.04 sh) ignores for -c commands (which seems to be how make uses it) so it doesn't do anything.

make -p will also interest you, which prints the values of set variables.

CMake generated Makefiles always support VERBOSE=1

As in:

mkdir build
cd build
cmake ..
make VERBOSE=1

Dedicated question at: Using CMake with GNU Make: How can I see the exact commands?

好久不见√ 2024-11-10 17:50:36

由自动工具生成的库 makefile(您必须发出的 ./configure)通常有一个详细选项,所以基本上,使用 make VERBOSE=1make V=1 应该会给你完整的命令。

但这取决于 makefile 是如何生成的。

-d 选项可能会有所帮助,但它会给你一个非常长的输出。

Library makefiles, which are generated by autotools (the ./configure you have to issue) often have a verbose option, so basically, using make VERBOSE=1 or make V=1 should give you the full commands.

But this depends on how the makefile was generated.

The -d option might help, but it will give you an extremely long output.

注定孤独终老 2024-11-10 17:50:36

从 GNU Make 版本 4.0 开始,--trace 参数是告诉 makefile 做什么以及为什么做什么的好方法,输出如下行

makefile:8: target 'foo.o' does not exist

makefile:12: update target 'foo' due to: bar

Since GNU Make version 4.0, the --trace argument is a nice way to tell what and why a makefile do, outputing lines like:

makefile:8: target 'foo.o' does not exist

or

makefile:12: update target 'foo' due to: bar
新人笑 2024-11-10 17:50:36

使用 make V=1

这里的其他建议:

  • make VERBOSE=1 - 至少在我的试验中不起作用。
  • make -n - 仅显示逻辑操作,而不显示正在执行的命令行。例如 CC source.cpp

  • make --debug=j - 也可以,但也可能启用多线程构建,导致额外的输出。

Use make V=1

Other suggestions here:

  • make VERBOSE=1 - did not work at least from my trials.
  • make -n - displays only logical operation, not command line being executed. E.g. CC source.cpp

  • make --debug=j - works as well, but might also enable multi threaded building, causing extra output.

暗喜 2024-11-10 17:50:36

我喜欢使用:

make --debug=j

https://linux.die.net/man/1/make

--debug[=FLAGS]

除了正常处理之外还打印调试信息。如果省略 FLAGS,则行为与指定 -d 相同。 FLAGS 可以是 a 表示所有调试输出(与使用 -d 相同),b 表示基本调试,v 表示更详细的基本调试,< code>i 用于显示隐式规则,j 用于调用命令的详细信息m 用于在重新制作 makefile 时进行调试。

I like to use:

make --debug=j

https://linux.die.net/man/1/make

--debug[=FLAGS]

Print debugging information in addition to normal processing. If the FLAGS are omitted, then the behavior is the same as if -d was specified. FLAGS may be a for all debugging output (same as using -d), b for basic debugging, v for more verbose basic debugging, i for showing implicit rules, j for details on invocation of commands, and m for debugging while remaking makefiles.

埋情葬爱 2024-11-10 17:50:36

根据您的 automake 版本,您还可以使用以下命令:

make AM_DEFAULT_VERBOSITY=1

参考:AM_DEFAULT_VERBOSITY

注意:我添加了此答案,因为 V=1 对我不起作用。

Depending on your automake version, you can also use this:

make AM_DEFAULT_VERBOSITY=1

Reference: AM_DEFAULT_VERBOSITY

Note: I added this answer since V=1 did not work for me.

偏爱自由 2024-11-10 17:50:36
  • 如果您想查看默认目标运行的所有命令(包括已编译的命令):
make --always-make --dry-run
make -Bn
  • 显示下次运行 make 时执行的命令:
make --dry-run
make -n

您可以自由选择本例中默认目标以外的目标。

  • In case you want to see all commands (including the compiled ones) of the default target run:
make --always-make --dry-run
make -Bn
  • show commands executed the next run of make:
make --dry-run
make -n

You are free to choose a target other than the default in this example.

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