如何强制 make/GCC 显示命令?
我正在尝试调试编译问题,但我似乎无法让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
调用试运行:
这将显示
make
正在尝试执行的操作。To invoke a dry run:
This will show what
make
is attempting to do.构建系统独立方法
是另一种选择。示例
Makefile
:输出:
这为
make
设置特殊的SHELL
变量,-x
告诉sh
在执行之前打印扩展行。相对于
-n
的一个优点是它实际上运行命令。我发现对于某些项目(例如 Linux 内核),-n
可能会比平常更早停止运行,可能是因为依赖性问题。此方法的一个缺点是您必须确保将使用的 shell 是
sh
,这是 Make 使用的默认 shell,因为它们是 POSIX,但可以使用进行更改SHELL
使变量。执行
sh -v
也很酷,但是 Dash 0.5.7 (Ubuntu 14.04sh
) 会忽略-c
命令(这似乎是make
使用它的方式),所以它不做任何事情。make -p
您也会感兴趣,它打印设置变量的值。CMake 生成的 Makefile 始终支持
VERBOSE=1
如:
专用问题:将 CMake 与 GNU Make 结合使用:如何查看确切的命令?
Build system independent method
is another option. Sample
Makefile
:Output:
This sets the special
SHELL
variable formake
, and-x
tellssh
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 theSHELL
make variable.Doing
sh -v
would be cool as well, but Dash 0.5.7 (Ubuntu 14.04sh
) ignores for-c
commands (which seems to be howmake
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:
Dedicated question at: Using CMake with GNU Make: How can I see the exact commands?
由自动工具生成的库 makefile(您必须发出的
./configure
)通常有一个详细选项,所以基本上,使用make VERBOSE=1
或make V=1
应该会给你完整的命令。但这取决于 makefile 是如何生成的。
-d
选项可能会有所帮助,但它会给你一个非常长的输出。Library makefiles, which are generated by autotools (the
./configure
you have to issue) often have a verbose option, so basically, usingmake VERBOSE=1
ormake 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.从 GNU Make 版本 4.0 开始,
--trace
参数是告诉 makefile 做什么以及为什么做什么的好方法,输出如下行:
Since GNU Make version 4.0, the
--trace
argument is a nice way to tell what and why a makefile do, outputing lines like:or
使用
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.我喜欢使用:
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:
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, andm
for debugging while remaking makefiles.根据您的 automake 版本,您还可以使用以下命令:
参考:AM_DEFAULT_VERBOSITY
注意:我添加了此答案,因为
V=1
对我不起作用。Depending on your automake version, you can also use this:
Reference: AM_DEFAULT_VERBOSITY
Note: I added this answer since
V=1
did not work for me.make
时执行的命令:您可以自由选择本例中默认目标以外的目标。
make
:You are free to choose a target other than the default in this example.