C/C++可以将所有动态库构建为一个二进制文件吗?

huangapple go评论85阅读模式
英文:

Can C/C++ build all dynamic libraries into one bin file?

问题

当我在不同的操作系统上开发时,我发现在一个Linux系统上构建的程序无法在另一个系统上运行,这是因为不同的libc版本。

我该如何像Go语言在C/C++中那样构建包含所有共享库的程序?

包括libc和libcxx。

英文:

When I develop across different OS's I find that a program built on one Linux system can not be run on another system, due to the different libc version.

How can I build in all the shared libraries just like golang did in c/c++?

Including libc and libcxx

答案1

得分: 2

如果你想在多个Linux系统上运行,你只需要使用其中任何一个系统中最旧的glibc进行构建即可。最简单的方法是从像CentOS 5这样的旧系统中下载一个虚拟机镜像,然后在那里进行构建。你不需要担心静态链接,只需针对旧版本进行构建,就能与较新版本基本兼容。

英文:

If you want to run on multiple Linux systems, all you really need is to build using the oldest glibc from any of them. The easiest way is to simply download a virtual machine image from an old system like CentOS 5 and build there. You don't need to worry about static linking, just building against an old version will mean you are mostly compatible with newer versions.

huangapple
  • 本文由 发表于 2016年11月25日 17:01:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/40801097.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定