tags:

views:

87

answers:

2

if I understand the gcc manuals right than the option -print-prog-name should print the name of the program used.

But it seems that this option only echoes the given argument

Examples:

gcc -print-prog-name=ld
--> ld

gcc -print-prog-name=xxxsome-funny-name
--> xxxsome-funny-name

Is this the expected behaviour? I think it should print something like

gcc -print-prog-name=ld
--> /usr/bin/ld

gcc -print-prog-name=xxxsome-funny-name
--> unknown program

EDIT: testing on Debian Lenny 64bit with gcc v4.2.4

A: 

I think the -print-prog-name option only applies to a small set of tools that GCC uses internally. For example,

$ gcc -print-prog-name=cc1
/usr/libexec/gcc/x86_64-redhat-linux/3.4.5/cc1

$ ls -L /usr/libexec/gcc/x86_64-redhat-linux/3.4.5/
cc1  cc1plus  collect2  f771  jc1  jvgenmain
$ gcc -print-prog-name=f771
/usr/libexec/gcc/x86_64-redhat-linux/3.4.5/f771

So gcc -print-prog-name is aware of the tools that live in that directory. But:

$ gcc -print-prog-name=ld
ld

My guess is that if gcc -print-prog-name returns an absolute path, it's configured to use that version of the program, no matter what's on your $PATH -- otherwise it just echoes back what you gave it without resolving it to an absolute pathname.

Jim Lewis
To add, ld is a part of binutils, NOT GCC. So GCC just invokes it as an external program instead of a known place (which is why you get a global path instead of direct one)
LiraNuna
A: 

Meanwhile I found another reason for the behaviour of

gcc -print-prog-name=ld

The ld command is not invoked directly by gcc.

gcc invokes collect. And it is collect which in turn invokes ld.