On 24 August 2012 08:46, naga raj wrote: > Hi, > > I have ported Gcc-4.6.2 to an embedded target. My C++ compiler is > generating huge code size. > > #include <iostream> > using namespace std; > int main() > { > return 0; > } > > If we execute the above program then all the function in the > iostream library are included in the elf as a result size of elf is > increased.... Including <iostream> causes global objects to be constructed, so even though you're not explicitly using std::cout or std::cin, those streams are initialized and code is run (before main) just because <iostream> is included. If you don't need to use it then don't include it. If you do need to use it then obviously the code size is larger if you use I/O features than if you don't use them. That said, libstdc++ isn't really optimised for embedded systems. Some configure-time options such as building libstdc++ without exceptions can help reduce code size, if you don't need to use exceptions. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43852 would also help avoid dependency on the I/O facilities.