Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way to make gcc omit crtbegin.o/crtend.o?

Tags:

c++

c

linux

gcc

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?

like image 842
R.. GitHub STOP HELPING ICE Avatar asked Nov 11 '10 06:11

R.. GitHub STOP HELPING ICE


1 Answers

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" "$@"'
like image 59
R.. GitHub STOP HELPING ICE Avatar answered Nov 15 '22 20:11

R.. GitHub STOP HELPING ICE