首页 > 解决方案 > How can I solve libstdc++ portability problem

问题描述

I have built a binary that runs in my system(fedora 30), but when I want to run that on ubuntu I get below error:

/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./App)

what is the standard way to solve this problem? or do I always need to rebuild my app on various os to run it?

标签: c++g++dynamic-linking

解决方案


what is the standard way to solve this problem?

The standard way to solve this is to define your minimum requirements, and then build your binary in such a way that it only requires this minimum, and nothing else.

For example, if you build your program on a RedHat 7.2 distribution, and don't use C++, your program will run on all Linux distributions that are not older than 20 years.

or do I always need to rebuild my app on various os to run it?

You don't.

In the particular case of GLIBCXX_3.4.26 version symbol, you have built your binary with GCC 9.0.0 (or later): see the ABI document.

The binary will not run on any system with only GCC-8.x runtime installed.

One way to avoid this requirement is to link with -static-libstdc++ flag. Your binary will be larger (possibly much larger), and it may require to be distributed in a different form (due to the viral nature of GPL; check with your lawyer), but it will work on older distributions.

Alternatively, if you build your binary "regularly" on a GCC-8.x based distribution, the binary should work just fine on a GCC-9.x based newer one.

Another solution for this is to distribute your binary in a docker container that has all the prerequisites.

P.S. I don't suggest that you actually run a physical RedHat-7.2 host. Using an isolated VM with an old distribution just for building should work.


推荐阅读