Linux C ++可移植二进制问题 [英] Linux c++ portable binary issue

查看:125
本文介绍了Linux C ++可移植二进制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我的二进制文件及其所有共享库打包到一个归档文件中.我希望用户仅提取存档以使二进制文件起作用.该可执行文件是通过Shell脚本启动的,在该脚本中,我将LD_LIBRARY_PATH设置为存档中包含的共享库路径.

I try to package my binary and all its shared libraries into an archive. I want user only extracts the archive to make the binary work. The executable is launched via a shell script where I set LD_LIBRARY_PATH to shared library path contained in the archive.

第一次,我想使其在RHEL 6.7发行版上运行,因此我已使用该发行版编译了二进制文件,并且在我对其进行测试时,它运行良好. 问题是我现在必须使其在RHEL 7.2上运行(并保持RHEL 6.7正常工作),并且当我启动二进制文件时它不起作用...它在glibc函数内崩溃(在参数中没有垃圾的isspace) . 我看到这两个RHEL版本背后的glibc版本已更改. 在存档中包含的共享库中,没有glibc共享库,因此我尝试添加它,现在出现以下错误:

On a first time I wanted to make it work on a RHEL 6.7 distribution so I have compiled my binary with this distribution, and when I tested it it works well. The problem is that I have now to make it work on a RHEL 7.2 (and keep RHEL 6.7 working) and when I launched the binary it don't work... it crashes inside a glibc function (isspace with no garbage in argument). I see that behind these two RHEL releases glibc version has changed. In the shared libraries that are contained in the archive there was not glibc shared library, so I tried to add it and now I got the following error :

./XXX: ���:ELF: zR: Error 892688562

这似乎是一个ELF错误(每次启动时都会出现详细信息),我检查了所有共享库,它们都是x64库(如二进制文件)... 我不想在RHEL 7.2上进行编译,因为我有很多依赖关系,而且我不想编译所有这些,并且对我来说维护一个版本也更容易.

It seems to be an ELF error (verbose is present each time I launch it), I check all my shared libraries and they are x64 libraries (like the binary)... I don't want to compile on RHEL 7.2 because I have a lot of dependancies and I don't want to compile all of it, and also it is easier for me to maintain one version.

我尝试了很多诸如Statifier和Ermine之类的方法,它们都可以工作,但是前者有一个错误,必须禁用地址空间布局随机化",而后者则是共享软件,我更喜欢免费的解决方案.我还尝试了CDE,它也可以工作,但是它会生成一个很大的包,有点混乱...

I tried many things like Statifier and Ermine, that both work but the first has a bug and have to had Address Space Layout Randomization disabled and the second one is a shareware and I prefer a free solution. I also tried CDE that also work, but it generates such a big package, it is a bit a mess...

为什么使用这种解决方案有效,而使用我自己的解决方案却无效?我做得不好吗?

Why with this kind of solution it works and with my homemade solution it don't work ? What am I not doing well ?

感谢您阅读, 我希望有人为我提供解决方案,因为我搜索了很长时间...

Thank you for reading, I hope someone has a solution for me because I search for a long time...

在我的shell脚本像这样之前,我找到了解决方案:

I found solution, before my shell script was like :

# Binary location
LOCATION=$(dirname $0)
# Shared libraries directory
BINDIR=${LOCATION}/bin/
# Define LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${BINDIR}:${LD_LIBRARY_PATH}
# Launch binary
${LOCATION}/XXX $*

我更改了:

# Binary location
LOCATION=$(dirname $0)
# Shared libraries directory
BINDIR=${LOCATION}/bin/
# Changed shared library default location and launch binary
${BINDIR}/ld-linux-x86-64.so.2 --library-path ${BINDIR} ${LOCATION}/XXX $*

我真的不明白为什么会这样,但是它可以奏效,有人可以向我解释一下吗? (ld-linux-x86-64.so.2来自RHEL 6.7发行版)

I don't really understand why but it works, someone can explain me please ? (ld-linux-x86-64.so.2 came from RHEL 6.7 distribution)

推荐答案

我真的不明白为什么会这样,但是它可以奏效,有人可以向我解释一下吗?

I don't really understand why but it works, someone can explain me please ?

此处进行了说明.您的解决方案是在此处中提到的显式加载器调用".

It's explained here. Your solution is "explicit loader invocation" mentioned here.

顺便说一句,这是错误的:${LOCATION}/XXX $*您应该改为这样做:

BTW, this is wrong: ${LOCATION}/XXX $* You should do this instead:

${LOCATION}/XXX "$@"

(您的变体将无法正确处理带有嵌入式空格的参数.)

(Your variant will not handle arguments with embedded spaces correctly.)

这篇关于Linux C ++可移植二进制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆