如何强制make / gcc来显示命令?

我试图debugging一个编译问题,但我似乎无法得到GCC(或者也许它是制造??)向我展示它正在执行的实际编译器和链接器命令。 这是我看到的输出:

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”这样的东西。 我不知道如何控制这种行为。

为了调用干运行

 make -n 

这将显示正在尝试做什么。

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

但这取决于生成文件的生成方式。

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

build立系统独立的方法

 make SHELL='sh -x' 

是另一种select。 示例Makefile

 a: @echo a 

输出:

 + echo a a 

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

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

这种方法的一个缺点是你必须确保使用的shell是sh ,这是Make使用的默认的shell,因为它们是POSIX,但是可以用SHELL makevariables来改变。

sh -v也会很酷,但是Dash 0.5.7(Ubuntu 14.04 sh )忽略了-c命令(这似乎是怎么使用它),所以它什么也不做。

make -pmake -p你感兴趣,它会打印设置variables的值。

CMake生成Makefiles

 make VERBOSE=1 

请参阅: 使用CMake和GNU Make:我怎样才能看到确切的命令?

由于GNU Make版本4.0,– --trace参数是一个很好的方式来告诉一个makefile做什么,为什么输出这样的行:

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

要么

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