链接共享库,而无需实际拥有它 [英] Linking shared libraries without actually having it

查看:400
本文介绍了链接共享库,而无需实际拥有它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这是使用的位于共享库交叉编译臂总成code:/system/lib/libxyz.s​​o(主机设备),并使用动态链接:/系统/斌/连接体 - 其也位于主机设备上

I'm trying to cross-compile arm assembly code which is using shared library that's located in : /system/lib/libxyz.so (on host device), and using dynamic linker: /system/bin/linker - which is also located on host device.

所以我编译:

arm-eabi-gcc -mcpu="cortex-a9"  -Wl,-dynamic-linker=/system/bin/linker -llibxyz.so -Wl,--unresolved-symbols=ignore-all -nostdlib topsecret.S -o topsecret

我还使用:

-Wl,--unresolved-symbols=ignore-all

要忽略任何未定义符号,因为我真的不有他们在编译时 - 我正在对ASM code正确地址的主叫

To ignore any undefined symbols as I dont really have them when compiling - I'm taking on the asm code the calling of right addresses.

我得到的微不足道的错误是:

The trivial error I'm getting is :

arm-eabi/bin/ld cannot find -llibxyz.so, collect2: ld returned 1 exit status

和我不actally希望有libxyz.s​​o库,我希望编译器忽略错误,并添加依赖性ELF头。
我试过轮候册, - 无按需,轮候册, - 按需论点,但没有帮助

And I dont actally want to have the libxyz.so library, I want the compiler to ignore the error, and add the dependency to the ELF Header. I tried -Wl,--no-as-needed, -Wl,--as-needed arguments but that didn't help.

现在的问题是,如果我可以忽略错误,假图书馆,或任何其他解决方案,这将给我已经在头文件的依赖良好的二进制文件。

The question is if I can either ignore the error, fake the library, or any other solution which will give me good binary that has the dependency in the header.

链接共享在GCC库没有文件?
该解决方案是不是一件好事,因为我不想改变ASM code,只有编译机制。

Link shared library in gcc without file? This solution is not good because I dont want to change the asm code, only the compiling mechanism.

推荐答案

很抱歉,但你想做的事是不可能的。链接器希望看到共享库,所以它知道哪些符号的定义存在,哪些不是;它需要知道,要理解的联动将如何工作。你必须目标的共享库复制到您的开发系统,或者使用显式加载在你参考答案(的dlopen等)提出并创建对dlsym联动自己()。 - MadScientist

Sorry, but what you want to do is not possible. The linker wants to see the shared library so it knows which symbols are defined there and which are not; it needs to know that to understand how the linkage will work. You'll have to copy the target's shared library to your development system, or else use explicit loading as suggested in the answer you reference (dlopen etc.) and create the linkage yourself with dlsym(). – MadScientist

您可以将文件从主机建立转移。如果您水湿做到这一点,那么有没有办法让连接器知道在一个未解决的符号存在的库,你可以创建一个垫片实施一个假主机库。这甚至会工作,如果你不能转移主机库(主机锁定或东西)。这将允许您在构建机上的链接,它应该修补主机其装载机的全面实施。 - 烂漫的噪音

You can transfer the file from host to build. If you cann't do this, then there is no way for the linker to know which library an un-resolved symbol exists in. You can create a fake host library with shims for implementation. This will work even if you can not transfer the host library (host locked down or something). This will allow you to link on the build machine and it should patch to the full implementation on the host by its loader. – artless noise

这篇关于链接共享库,而无需实际拥有它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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