Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the C++ standard library libstdc++.so file size

Tags:

c++

I have different C++ compilers on my computer, each compiler has its own libstdc++.so and their size is different.

-rwxr-xr-x. 1 root root 967K Mar 22  2017 libstdc++.so.6.0.13
-rwxr-xr-x. 1 root root 6.5M Aug  1  2017 libstdc++.so.6.0.20
-rwxr-xr-x. 1 root root  11M Aug  1  2017 libstdc++.so.6.0.21
-rwxr-xr-x. 1 root root  12M Jan 30 16:58 libstdc++.so.6.0.24

I want to know why libstdc++.so.6.0.13 is so much smaller than others, and is there any way to reduce others' size. I will be glad if some one can help me.

like image 858
CyrusChen Avatar asked May 29 '18 09:05

CyrusChen


People also ask

What's libstdc++?

Libstdc++ is the standard C++ library. It is needed to compile C++ code (part of GCC is written in C++), but we had to defer its installation when we built gcc-pass1 because it depends on glibc, which was not yet available in /tools. Approximate build time: 0.5 SBU. Required disk space: 878 MB.

Where is Libstdc ++ located?

This happens even when the libstdc++ is installed and the file is available in /usr/local/lib/libstdc++.so. By default, the ds_agent looks for the required library in the /opt/ds_agent/lib folder.

What is Libsupc?

Libsupc++ is a support library for g++ that contains functions dealing with run-time type information (RTTI) and exception handling. If you attempt to use either exceptions or RTTI in a C++ kernel you have compiled with a GCC Cross-Compiler you will also need the libsupc++ library.


Video Answer


1 Answers

The versioning scheme of libstdc++ is misleading, the differences between these versions are actually huge when you consider the corresponding GCC versions:

  • GCC 4.4.2: libstdc++.so.6.0.13 (October 15, 2009)
  • GCC 4.9.0: libstdc++.so.6.0.20 (April 22, 2014)
  • GCC 5.1.0: libstdc++.so.6.0.21 (April 22, 2015)
  • GCC 7.2.0: libstdc++.so.6.0.24 (August 14, 2017)

There's been the C++14 implementation between GCC 4.4 and 4.9, and major work on C++17 and various experimental proposals after that.

From libstdc++'s FAQ:

Usually the size of libraries on disk isn't noticeable...

. . . the object files in question contain template classes and template functions, pre-instantiated, and splitting those up causes severe maintenance headaches.

So in short - not much can be done about the size. If you're really interested, you can see what's inside using readelf -a libname.so

You can always downgrade to an older GCC version which will come with a smaller libstdc++.

Having said that, on Ubuntu the size of libstdc++.so.6.0.24 is 1.54MB, so it didn't actually grow that much. There could be something wrong with your specific distro or maybe you grabbed a debug version. You can try stripping debug symbols with strip libstdc++.so.6.0.24 (the strip utility is part of binutils).

like image 62
rustyx Avatar answered Oct 27 '22 00:10

rustyx