rpath=$ORIGIN 没有想要的效果? [英] rpath=$ORIGIN not having desired effect?

查看:30
本文介绍了rpath=$ORIGIN 没有想要的效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二进制CeeloPartyServer";需要在运行时在 FreeBSD 机器上找到 libFoundation.so.它们都在同一个目录中.我使用链接器标志 -rpath=$ORIGIN 编译(在另一个平台上,使用交叉编译器)CeeloPartyServer.

I've got a binary "CeeloPartyServer" that needs to find libFoundation.so at runtime, on a FreeBSD machine. They're both in the same directory. I compile (on another platform, using a cross compiler) CeeloPartyServer using linker flag -rpath=$ORIGIN.

> readelf -d CeeloPartyServer |grep -i rpath
 0x0000000f (RPATH)                      Library rpath: [$ORIGIN]
> ls
CeeloPartyServer    Contents        Foundation.framework    libFoundation.so
> ./CeeloPartyServer 
/libexec/ld-elf.so.1: Shared object "libFoundation.so" not found, required by "CeeloPartyServer"

为什么我尝试运行它时找不到库?

Why isn't it finding the library when I try to run it?

我的确切链接器行是:-lm -lmysql -rpath=$ORIGIN.

My exact linker line is: -lm -lmysql -rpath=$ORIGIN.

我很确定我不必转义 $ 或类似的东西,因为我的 readelf 分析确实表明库 rpath 设置为 $ORIGIN.我错过了什么?

I am pretty sure I don't have to escape $ or anything like that since my readelf analysis does in fact show that library rpath is set to $ORIGIN. What am I missing?

推荐答案

我假设你使用的是 gcc 和 binutils.

I'm assuming you are using gcc and binutils.

如果你这样做

readelf -d CeeloPartyServer | grep ORIGIN

您应该返回上面找到的 RPATH 行,但您还应该看到一些关于标志的条目.以下来自我构建的一个库.

You should get back the RPATH line you found above, but you should also see some entries about flags. The following is from a library that I built.

0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../lib]
0x000000000000001e (FLAGS)              ORIGIN
0x000000006ffffffb (FLAGS_1)            Flags: ORIGIN

如果您没有看到某种 FLAGS 条目,您可能没有告诉链接器将该对象标记为需要原始处理.使用 binutils ld,您可以通过传递 -z origin 标志来做到这一点.

If you aren't seeing some sort of FLAGS entries, you probably haven't told the linker to mark the object as requiring origin processing. With binutils ld, you do this by passing the -z origin flag.

我猜你正在使用 gcc 来驱动链接,所以在这种情况下,你需要通过将 -Wl,-z,origin 添加到你的 gcc 链接来通过编译器传递标志行.

I'm guessing you are using gcc to drive the link though, so in that case you will need to pass flag through the compiler by adding -Wl,-z,origin to your gcc link line.

这篇关于rpath=$ORIGIN 没有想要的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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