388

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hernejj
  • 3,889
  • 2
  • 15
  • 3
  • Are you running a makefile, or just a `gcc` command? – Blender Apr 28 '11 at 14:36
  • 30
    This looks like [Kbuild](https://www.kernel.org/doc/linux/README) or [Autotools](https://www.gnu.org/software/automake/manual/html_node/Automake-Silent-Rules.html) output. Try ***`make V=1`***. – jww Mar 21 '16 at 02:10
  • 1
    Related: the opposite question [Control the output of a make command to be less verbose, don't echo each command](https://stackoverflow.com/questions/8438661/control-the-output-of-a-make-command) – smci Mar 14 '18 at 10:54

8 Answers8

375

To invoke a dry run:

make -n

This will show what make is attempting to do.

Zombo
  • 1
  • 62
  • 391
  • 407
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
237

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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • 17
    Definitely the best answer which doesn't depend on how well the original Makefile was written/generated – nodakai Oct 21 '15 at 02:51
  • 2
    If anyone can explain the downvote, let me know so I can learn and improve the information ;-) – Ciro Santilli OurBigBook.com Oct 21 '15 at 14:59
  • 1
    make `SHELL='$$SHELL -x'` will make `$SHELL` literal which is not evaluated. Using `make SHELL="$SHELL -x"` will work. – Rick van der Zwet Feb 03 '16 at 14:16
  • 1
    this is the best generic answer, in contrast to some other answers this does not depend on using cmake – Mike76 Nov 19 '18 at 10:02
  • 2
    make SHELL='sh -x' is super! – Jackie Yeh Dec 11 '18 at 10:33
  • Good idea (`SHELL='sh -x'`), but if your makefiles were to pass `SHELL` around, they must do it like so: `SHELL='$(SHELL)'`, not `SHELL=$(SHELL)`. So you might need to do some replacements. – x-yuri Apr 29 '19 at 14:41
  • I don't know why the downvote, but there should be a makefile interface that can circumvent this. There are many options as expressed in other posts. However, the makefile may contain `make help`, which would give instruction on how to get verbose output. Using the `sh -x` could break a makefile if it wanted `bash` for instance. There is no right answer. I always take a negative vote as a fact that I may have stretched someone's mind and they didn't like it. – artless noise Mar 16 '22 at 21:30
  • 1
    `SHELL += -x` might be a better tack. – artless noise Mar 16 '22 at 22:18
215

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gui13
  • 12,993
  • 17
  • 57
  • 104
38

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
Flow
  • 23,572
  • 15
  • 99
  • 156
Julien Palard
  • 8,736
  • 2
  • 37
  • 44
  • 2
    This argument prints more detailed information than dry run. It is very helpful to understand make systems which has complex build process like dpdk. – makerj Jul 29 '17 at 15:06
  • @makerj: Perhaps, but it does actually execute the commands, unlike `make -n`. – einpoklum Jun 30 '20 at 12:46
31

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.

TarmoPikaro
  • 4,723
  • 2
  • 50
  • 62
  • 9
    `make VERBOSE=1` is for CMake. Your trials were most likely with GNU autotools-based projects. – Ruslan Dec 15 '18 at 19:01
18

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.

14

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ru Hasha
  • 876
  • 1
  • 7
  • 16
1
  • 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.

abu_bua
  • 1,361
  • 17
  • 25