views:

500

answers:

1

How can I get the command line GCC uses to invoke ld?

I have a problem for an AVR target where GCC apparently adds a linker option which I am trying to override, so I would like to look at the exact options GCC uses for ld.

+6  A: 

Use gcc -v to see what commands it runs. As in,

gcc -v -o hello hello.c

This will print a lot of output, including the linker command. The actual output depends on the platform, but the linking command should be near the end. Alternatively, use

gcc -### -o hello hello.c

This is like -v, but does not actually run any commands and quotes the options.

Another option is

gcc -dumpspecs

Look for the entry for link.

The above command line flags are listed in gcc --help and explained on the man page. Here's GCC documentation for the spec files.

Ville Laurikari
Or use gcc -### which is similar to -v but does not actually execute anything ant quotes all args
Laurynas Biveinis
Thanks! I edited the post to mention also gcc -###.
Ville Laurikari