链接到调用其他共享库的共享库 [英] Linking to shared libraries that call other shared libraries

查看:155
本文介绍了链接到调用其他共享库的共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用libusb编写/构建的共享库

I have a shared lib that i've written/built that uses libusb

在构建时,我必须与libusb共享库链接-到目前为止非常简单

when i build that i have to link with the libusb shared lib - so far so straightforward

但是如果我随后编写/构建一个使用共享库的exe,则在构建该exe时我也必须链接到libusb

but if i then write/build an exe that uses my shared lib, when i build that exe do i have to link to libusb as well

只要共享的lib知道在哪里可以找到libusb,我就会以为答案应该是

i would have thought the answer should be no, as long as my shared lib knows where to find libusb that should be fine

但实际上,答案是肯定的,exe确实必须链接到libusb或它抱怨找不到我共享的lib调用的libusb函数的引用.

but in practice, the answer is yes, the exe does have to link to libusb or it complains it can't find references to the libusb functions that my shared lib calls.

为什么我的exe文件需要链接到libusb以及共享库-当然,它应该将责任转交给共享库,而不必担心吗?

why should my exe need to link to libusb as well as the shared lib - surely it should devolve responsibility to the shared lib and not have to worry about it?

更新:

尝试对其进行可视化:

myexe
 |
 | links to:
 |
mylib.so
 |
 | links to:
 |
libusb-1.0.so

在我看来,myexe还必须显式链接到libusb-1.0,因为以前的链接已经隐含了这一知识吗?

it seems superfluous to me that myexe also has to explicitly link to libusb-1.0 as this knowledge is already implicit from previous linking?

澄清一下,myexe仅 调用了mylib.so中定义的函数,它没有直接"调用任何libusb-1.0函数.对libusb-1.0函数的唯一调用是通过mylib.so中的函数进行的.

to clarify, myexe only calls functions defined in mylib.so, it doesn't call any libusb-1.0 functions 'directly'. The only calls to libusb-1.0 functions are made from functions in mylib.so

推荐答案

是的,理论上您也必须链接您的libusb.但是有些工具,例如libtool,可以使第三级库依赖关系链接自动化.因此,当您链接mylib.so

Yes, in theory you have to link your libusb as well. But there are tools like libtool which can automate the third level library dependency linking. So libtool will link libusb automatically when you link your mylib.so

请参阅 http://www.gnu.org/software /libtool/manual/html_node/Inter_002dlibrary-dependencies.html

这篇关于链接到调用其他共享库的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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