libstdc++ is 729,136 bytes on gcc 3.3.2 at least. Therefore it would be nice for embedded systems to be able to get rid of it for c++ programs. There is a subset of libstdc++ called libsupc++ which you can statically link to your programs, for the core stuff like the operators new & delete and exceptions. (libsupc++ is actually linked into libstdc++) If you require the STL etc. then you need the full lib. The following creates a dynamic executable as before but without dependency on libstdc++:$gcc -O3 -nostdlib `for doto in crt{1,i,begin,end,n}.o; do \ g++ -print-file-name=$doto; done` supc++.cpp -lsupc++ -lgcc_s -lm -lcI was able to determine the libs to use above by looking at the output from the -v option to a standard g++ build. You can vary the build for shared, static, ... to get the appropriate libs. Note a static build is not usually practical with glibc due to the size, however ulibc or dietlibc etc. can be used. If you don't need any exceptions (-fno-exceptions) and also you don't use new or delete then you don't need supc++ or gcc_s (libgcc_s.so.1), though there is not much point using c++ at all without new and delete? Anyway libgcc_s.so.1 is only about 30K. Note however that the -fno-exceptions and -fno-rtti options reduce the size of your executable also. Taking this example program, the sizes are:
type | size | notes |
standard | 3404 | g++ -O3 supc++.cpp |
supc++ | 18012 | gcc -O3 -nostdlib ... |
-fno-exceptions | 17948 | |
-fno-rtti | 17948 | no size difference for this simple program |
© Jun 1 2004