交联于ARM / QNX失败,间接/传递依赖 [英] Cross-linking for ARM/QNX fails with indirect/transitive dependencies

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

问题描述

我试图编译QNX / ARM,它由一个主可执行文件和两个共享库,力霸和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.

主要仅依赖于利巴并不会从libb在所有使用任何东西。
力霸取决于libb。
因此,依赖链是:首页 - >力霸 - > libb。因此,libb是主要一个间接/传递依赖。
liba.so是在子目录力霸/,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和力霸。

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 丢失! 指定的路径,而的实际库。添加 -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 的通过运行时的从的力霸的使用的dlopen() >。

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

更新:

作为的 tmcguire 的指出,共享库间接链接的行为,从连接器到连接器而异。据这篇文章,负责 LD 选项为 - 无 - 复制 - DT-需要,项(有时也称为 - 无插件需要,其中在最新的 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.

另外一个有趣的选择是 - 按需

Another interesting option is --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天全站免登陆