GLIBCXX versions

狂风中的少年 提交于 2019-11-26 19:34:51

问题


If I compile a C++ program on my machine, and run it on another one (with older software) I get: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found.

In fact on my system glibc is newer (I got gcc-libs 4.5.1: libstdc++.so.6.0.14) and strings /usr/lib/libstdc++.so.6 | grep GLIBCXX prints from GLIBCXX_3.4 to GLIBCXX_3.4.14. On the other system, instead, it only prints up to GLIBCXX_3.4.8 (I got libstdc++.so.6.0.8).

So I've got a few questions:

  1. Why my linker links C++ binaries against libstdc++ version GLIBCXX_3.4.9 instead of GLIBCXX_3.4.14?

  2. If I complied my binary against libstdc++ version GLIBCXX_3.4 I guess it would run almost on everywhere. Would that imply any sort of issues? (eg: would it use older -and thus worse- algorithm implementations?)

  3. If instead I statically link my program against my libstdc++ I guess it will run everywhere; the binary will be a lot bigger (~1MB) of course, any other pros/cons?

  4. Can I force the linker to link my binary against a given version of libstdc++?


回答1:


Use readelf -a and objdump -x to inspect ELF files in preference to strings.

Actually, all the GLIBCXX_* versions don't apply to the entire library, but to each symbol (symbol versioning, see DSO-howto). So you can have e.g: std::char_traits<wchar_t>::eq@@GLIBCXX_3.4.5 and std::ios_base::Init::~Init()@@GLIBCXX_3.4 on the same library file.

The fact that your program needs GLIBCXX_3.4.9 probably means that it has been linked against a symbol that has been introduced/has changed semantics on GLIBCXX_3.4.9.




回答2:


  1. That the the library version that is installed on your system. You could manually build the glibc version 3.4.14 and link to it
  2. That depends. Maybe the later version fixed some issues. The users of your program would have to link against the version that your program requires
  3. The memory usage is higher
  4. Yes, pass proper parameter to the linker. If you need specific version of the library, then it is best to download it, and build it manually, and link to it.

EDIT

I just remembered that statically linked libraries increase the memory usage.




回答3:


In my opinion, if your binaries don't use the new features of newer GLIBCXX version, then they won't be linked with that version. So your binaries was linked with GLBCXX 3.4.9, there must be at least one symbol exported from it, and there're no any symbols exported from version newer than 3.4.9.



来源:https://stackoverflow.com/questions/4133674/glibcxx-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!