ARM/QNX 的交叉链接因间接/传递依赖项而失败 [英] Cross-linking for ARM/QNX fails with indirect/transitive dependencies

查看:21
本文介绍了ARM/QNX 的交叉链接因间接/传递依赖项而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 QNX/ARM 编译一个简单的项目,该项目由一个主可执行文件和两个共享库 liba 和 libb 组成.

I am trying to compile a simple project for QNX/ARM, which consists of a main executable and two shared libraries, liba and libb.

main 仅依赖于 liba,根本不使用 libb 中的任何内容.liba 依赖于 libb.所以依赖链是:main -> liba -> libb.因此,libb 是 main 的间接/传递依赖项.liba.so在子目录liba/中,libb.so在子目录libb/中.

main depends on liba only and does not use anything from libb at all. liba depends on libb. So the dependency chain is: main -> liba -> libb. Therefore, libb is a indirect/transitive dependency of main. liba.so is in the subdirectory liba/, libb.so is in the subdirectory libb/.

我通过以下方式链接主要内容:

I link main the following way:

qcc -Vgcc_ntoarmv7le -Wl,--no-undefined -lang-c++ -o linktest main.o -L$TARGET/lib -Llibb -Lliba -la

如您所见,由于有两个 -L 行,链接器应该可以轻松找到 libb 和 liba.

As you can see, because of the two -L lines, the linker should have no problem finding both libb and liba.

当我使用 QNX/ARM 工具链编译它时,出现错误:

When I compile this with the QNX/ARM toolchain, I get an error:

ntoarm-ld: warning: libb.so, needed by liba/liba.so, not found (try using -rpath or -rpath-link)

使用 strace 确认 ld 甚至从不查看 libb/目录,尽管这是用 -L 指定的.

Using strace confirms that ld never even looks into the libb/ directory, despite this being specified with -L.

为什么不查看这里的 -L 目录?

Why does it not look into the -L directories here?

推荐答案

-lb 缺失!L 指定路径,而l 实际库.在构建命令的末尾添加 -lb:

-lb is missing! L specifies the path, while l the actual library. Add -lb at the end of your build command:

qcc -Vgcc_ntoarmv7le -Wl,--no-undefined -lang-c++ -o linktest main.o \
-L$TARGET/lib -Llibb -Lliba -la -lb

如果您想消除这种构建时依赖性,请考虑通过运行时使用 libb 动态加载liba使用dlopen().

If you want to eliminate this build-time dependency, consider using libb via runtime dynamic loading from liba using dlopen().

更新:

正如 tmcguire 所指出的,共享库的间接链接行为因链接器而异.根据这篇文章,负责的ld选项是--no-copy-dt-needed-entries(有时称为 --no-add-needed,在最新的 gcc 版本(>4.5?)中启用默认情况下.

As tmcguire pointed out, behavior of indirect linking for shared libraries varies from linker to linker. According to this article, responsible ld option is --no-copy-dt-needed-entries (sometimes called --no-add-needed, which in latest gcc releases (>4.5?) is enabled by default.

另一个有趣的选项是--as-needed:

--as-needed 标志被传递给 GNU 链接器 (GNU ld).旗帜告诉链接器在生成的二进制文件中只链接库包含二进制文件本身实际使用的符号.这个二进制可以可以是最终的可执行文件或其他库.

The --as-needed flag is passed to the GNU linker (GNU ld). The flag tells the linker to link in the produced binary only the libraries containing symbols actually used by the binary itself. This binary can be either a final executable or another library.

其他阅读是这里此处.

这篇关于ARM/QNX 的交叉链接因间接/传递依赖项而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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