ld 和 lld 只使用我输入的路径

ld and lld use only paths I input

我正在尝试为我的 raspberry pi 进行交叉编译,不幸的是 pi 的 libstdc++ 版本比我的构建机器旧,当我尝试 运行 我的可执行文件时它说“./< exe_name>: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: 版本 `GLIBCXX_3.4.26' 未找到(./ 要求)。我明白了通过使用“-static”工作,但我真的希望能够告诉 ld(gcc linker)和 lld(clang linker)“只在这些路径中查找any 库”,它一直在寻找系统一并 link 反对它。我已经同步了 raspberry pi 的 /usr/lib 和 /lib 目录转到主机,我只想说“使用 /path_to_raspberry_pi_rsync/lib 和 /path_to_raspberry_pi_rsync/usr/lib”。

让 ld 和 lld 告诉我它在尝试 link.

时使用的路径的奖励积分

I'd like to be able to tell both ld (the gcc linker) and lld (the clang linker) "Only look in these paths for any libraries"

如果您提供适当的 -L/path/to/target/libraries 和足够的内容,两者都会这样做。

it keeps finding the system one and linking against it. I've rsynced the raspberry pi's /usr/lib and /lib directores over to the host machine and I'd like to say "use /path_to_raspberry_pi_rsync/lib and /path_to_raspberry_pi_rsync/usr/lib" only.

您的问题很可能是因为您rsync编辑的是运行时库,而不是实际的开发库。所以如果例如/path_to_raspberry_pi_rsync/usr/lib 包含 libstdc++.so.6,但 包含 libstdc++.so symlink,那么 link 人将继续寻找for libstdc++.so.,直到它在系统目录中找到一个。

addition 中,一旦您成功地将 link 限制为仅“rsync”d 库,您的 link 可能会失败未解析 libstdc++ 个符号。那是因为您需要一组 匹配 的 headers 和库。

您最好的选择是获得针对您的运行时环境的适当的工具链。

Bonus points for getting ld and lld to tell me what path it's using when it tries to link.

使用 ld,您可以添加 -Wl,-t 标志,它会告诉您它打开的每个库和 object 文件。 lld 也可能支持此标志。