One feature not so known about gcc are specs
files
gcc -dumpspecs >spec
output the built-in specs file
If we need to add some option, compile/link flag to be used always or on some condition we can add it to the dumped spec file, example:
*link:
-rpath /opt/someroot/lib
add always the rpath to the link options, we can try the spec file with the command line:
gcc -specs=spec test.c
readelf -d a.out |grep RPATH
on startup gcc/g++ look for a spec file on the filesystem, we can guess the full path with strace
and grep
:
strace -fF -o /tmp/g++.log g++ test.cpp
grep specs /tmp/g++.log
if we build our toolchain we can add a configure option --with-specs=
, the argument is a spec code, it isn’t shown on -dumpspecs
but will be used, example:
--with-specs="%{shared:-Wl,-rpath -Wl,$(DESTDIR)/lib}%{!shared:-Wl,-rpath -Wl,$(DESTDIR)/lib}"