crosstool-ng / crosstool-ng

A versatile (cross-)toolchain generator.
Other
2.14k stars 666 forks source link

Always link statically #1669

Open healytpk opened 2 years ago

healytpk commented 2 years ago

If you select uClibc for the standard C library, and then select "Build Static Toolchain", and then use the resultant toolchain to build a program like this:

whatever-platform-gcc -o prog prog.c

then the binary will be statically linked, you don't need to supply "-static" at the command line.

However if you choose glibc as the standard C library and select "Build Static Toolchain", then the binaries produced will link dynamically with glibc unless you specifically specify '-static' when building. Is this a known issue, or is it even by design?

I want to have a toolchain that uses glibc but also always links statically with glibc regardless of whether you supply '-static' at the command line or not. In order to achieve this behaviour, will I have to edit the toolchain settings for "extra config" and add "-static"? Or is there a better way?

healytpk commented 2 years ago

Sorry I realised this evening how clueless I am. The option "Build Static Toolchain" just makes the binaries such as arm-unknown-linux-gcc to be linked statically (i.e. it doesn't affect the binaries produced for the target architecture). I'm experimenting with a few different options here, I think I need to build glibc and all other built-in libraries with "-fPIC" so that the ".a" files can be used by shared libraries, and also have the host compiler always have "-shared -fPIC". I think that might work (my testing suggests it will). I'm building another cross-compiler now.