c++ - 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?
解决方案
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.
推荐阅读
- alias - 将别名中的路径存储到 GREP
- java - Spark SQL:加入后保留非键行
- javascript - 让 JS 在显示内容之前等到 wikipedia API 重定向
- javascript - 将文件拆分为base64较小的块时,Javascript结果不正确
- c# - 当 ItemsSource 更改 MVVM 时,Combobox SelectedItem 不会更新
- node.js - 为什么在将代码与 Webpack 捆绑后节点无法解析到文件夹的绝对路径
- serial-port - 与 USB 串行适配器不一致
- questdb - 如何自动删除 QuestDB 中的日志文件?
- c++ - 使用固定大小提升多精度整数保持基本类型行为
- reactjs - 在获取请求中隐藏 API 密钥