Is there an easy way to make gcc omit crtbegin.o/crtend.o?
Aside from using -nostdlib
and linking crt1.o -lc -lgcc
yourself, is there any easy way to prevent gcc from lin开发者_运维知识库king 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" "$@"'
I think you need the -nostartfiles
option. That's what I need for embedded stuff anyways.
精彩评论