Decoding gcc specs file line

490 Views Asked by At

I have a problem with the implicit LIBRARY_PATH modification of g++ between two versions (g++ -v gives this info). I set the LIBRARY_PATH to a single local directory where I have custom libraries. However, it turned out that only one version of the g++ (let's call it version A) correctly linked, the other (version B) linked to the system-default, which was not desired. Apparently, the order of directories was mixed up and my specification was not properly respected. It is a similar issue to LIBRARY_PATH not used before /usr/lib anymore in gcc 4.2 and later? although not with these versions.

Somehow I came along the idea to have a look at the specs files of the two different versions (got them via g++ -dumpspecs > specs). I then tried to see if running the version of g++ (B; that was producing the *un*expected modifications) with the specs file of the other version (A) would still yield that modification and to my relief the LIBRARY_PATH was now exactly as I expected it (matching version A)!

I further traced down the place of this weird modification to happen at the following line:

. !m64 !m32;.:../lib64 m64 !m32;.:../lib32 !m64 m32;

Besides appearing to affect the setting/modification of LIBRARY_PATH, I sadly have no clue what this line means. Therefore I hope that some of you is able to "decipher" this line and explain what it means so that I can try to modify it according to my requirements.

Thank you!

1

There are 1 best solutions below

2
On BEST ANSWER

That line affects how libraries are found relative to GCC's $PREFIX/lib directory (where $PREFIX is the directory GCC was installed to.)

There are three parts to it:

$PREFIX/lib/. is used when neither -m32 or -m64 is used on the command-line.

$PREFIX/lib/.:$PREFIX/lib/../lib64 is used when -m64 is used.

$PREFIX/lib/.:$PREFIX/lib/../lib32 is used when -m32 is used.

This suggests to me you are using Debian or Ubuntu, I don't think a vanilla GCC build from the FSF sources would have that in the specs. Were both your GCC versions from .deb packages or did you install them yourself? (The Multi Arch support in recent Debian/Ubuntu releases moves library directories and so breaks vanilla GCC, I think Debian and Ubuntu patch the GCC code for their .deb packages.)

Could you add the output of linking with g++ -v for each of your versions, to see the exact library search paths used by each version?

Also, why not just use -L instead of LIBRARY_PATH? Directories specified with -L always come first, before the system dirs or GCC's own dirs or the ones specified in LIBRARY_PATH.