简体   繁体   中英

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

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.

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM