使用 c++ 的不同 linux 发行版的问题可执行文件
我有一个 C++ 代码,可以在我的 Linux 机器(Ubuntu Karmic)上完美运行。 当我尝试在另一个版本上运行它时,我缺少各种共享库。
有没有办法将所有共享库合并到单个可执行文件中?
编辑: 我想我问错了问题。我应该要求一种方法来静态链接我的可执行文件(当它已经构建时)。 我在 ermine & 中找到了答案。 statifier
I have a c++ code that runs perfect on my linux machine (Ubuntu Karmic).
When I try to run it on another version, I have all sort of shared libraries missing.
Is there any way to merge all shared libraries into single executable?
Edit:
I think I've asked the wrong question. I should have ask for a way to static-link my executable when it is already built.
I found the answer in ermine & statifier
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
缺少共享库有 3 个可能的原因:
libz.so.1.2.3
并且另一台机器具有兼容的 API(主要版本1
),但不同的次要版本2.3 它就可能适用于您的程序
libc.so.2
与libc.so 不兼容.1
。修复方法是:
libz.so.1
而不是libz.so.1.2.3
。There are 3 possible reasons you have shared libraries missing:
libz.so.1.2.3
and the other machine has an API compatible (major version1
) but different minor version2.3
, which would probably work with your program if only it would linklibc.so.2
vslibc.so.1
.The fixes are:
libz.so.1
instead oflibz.so.1.2.3
.您所描述的是使用静态库而不是共享库。
What you are describing is the use of static libraries instead of shared libraries.
对于这里提到的原始问题,有几种技术解决方案,例如
或者
,但如果您处于 ISV 的位置,实际上只有一个明智的解决方案:
全新安装旧系统(例如,如果您的目标是桌面,则为 Ubuntu 6.x,也许可以追溯到 Red)如果您的目标是服务器,则为 Hat 9)并在此基础上构建您的软件。一般来说,库(当然还有 libc)是向后兼容的,因此在较新的系统上运行不会出现问题。
当然,如果您有非标准或最新版本的库依赖项,这并不能完全解决问题。在这种情况下,正如其他人所建议的那样,如果您想保持稳健,最好使用 dlopen() 并报告问题(或以减少的功能运行)。
There have been several technical solutions to the original problem noted here, e.g.
or
but if you're in the position of an ISV, there is really just one sane solution:
Get a clean install of an older system, (e.g. Ubuntu 6.x if you're targeting desktops, perhaps as far back as Red Hat 9 if you're targeting servers) and build your software on that. Generally libraries (and definitely libc) are backwards compatible, so you you won't have problems running on newer systems.
Of course if you have non-standard or recent-version lib dependencies this doesn't completely solve the problem. In that case, as other's have suggested, if you want to be robust it's better to dlopen() and report the problems (or run with reduced functionality).
我不太确定,但您可能想通过静态链接所有库来创建可执行文件。
I am not too sure, but you may want to create your executable by statically linking all the libraries.
一种替代方法是使用
dlopen()
动态加载共享库如果加载失败,请正常退出,并显示可执行文件需要依赖库才能工作的消息。然后用户可以安装适当的库。
One alternative is to dynamically load shared libraries using
dlopen()
and if it fails to load, exit gracefully with the message that the dependent library is required for the executable to work.The user then may install the appropriate library.
另一种可能的解决方案是使用 statifier (http://statifier.sf.net) 或 Ermine (http://magicErmine.com)
它们都能够将动态可执行文件及其所需的所有库打包到一个独立的可执行文件中
Another possible solution is using statifier (http://statifier.sf.net) or Ermine (http://magicErmine.com)
Both of them are able pack dynamic executable and all of it's needed libraries into one self-containing executable