RFC: An option to link against static gcc libraries

David Daney ddaney@avtrex.com
Fri Dec 30 19:58:00 GMT 2005


H. J. Lu wrote:
> On Fri, Dec 30, 2005 at 01:56:16PM -0500, Andrew Pinski wrote:
> 
>>On Dec 30, 2005, at 1:53 PM, H. J. Lu wrote:
>>
>>
>>>Gcc build executable linking against dynamic libraries by default.
>>>"-static" will link against all static libraries. For run-time
>>>portability, we may want to link against static gcc libraries, like
>>>libstdc++.a, libgfortran.a, libgcj.a, ...., but against dynamic system
>>>libraries, when we building executables. Currently, there is no easy
>>>way to do it. We have -static-libgcc for libgcc.a. It will be nice to
>>>have -static-gcclibs or something like that, to link against static
>>>gcc libraries.
>>
>>One, this will not work at all libobjc or libgcj since they
>>require lookups at runtime.
> 
> 
> Are you saying "gcc -static" doesn't work with libobjc and libgcj?
> 

I think that is what he is saying.

For the general case it is true.  However that does not mean that it is 
not a useful option.  For the libgcj case, if you know what you are 
doing and you do not need all the features of libgcj, static linking can 
be advantageous.

I would much rather do 'gcj -static-gcclibs' flag than do this:

'gcc -shared-libgcc -Wl,-non_shared -lgcj -Wl,-call_shared \
  -lsupc++ -Wl,--as-needed -lz -lgcc_s -lpthread -lc -lm -ldl \
-Wl,--no-as-needed'

Note that this is not a hypothetical case.  That is my actual linker 
command line.

David Daney.





More information about the Gcc mailing list