Aside from using -nostdlib
and linking crt1.o -lc -lgcc
yourself, is there any easy way to prevent gcc from linking crtbegin[S].o
and crtend[S].o
? These files are not that large, but I'm playing around with making small binaries, and would like to remove the useless C++ support code that's not needed for C programs. (Presumably, gcc links them even for C programs in case you're using a C++ library with global object variables. I'll spare everyone the rant about how it should be generating safe one-time initialization calls everywhere the global object is referenced in C++ modules rather than initializing global objects prior to main
...)
I wouldn't be opposed to hacking the gcc specs
file to make linking of the C++ support files conditional on such-and-such, but I'm not sure how I would do that. Perhaps there's already a nice way?
gcc -wrapper sh,-c,'z= ; for i ; do [ "$z" ] || set -- ; z=1 ;
case "$i" in *crtbegin*.o|*crtend*.o) ;; *) set -- "$@" "$i" ;; esac ;
done ; exec "$0" "$@"'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With