简体   繁体   English

共享库(.so)文件是否需要在链接时显示(或指定)?

[英]Do shared libraries (.so) files need to present (or specified) at link time?

Do shared libraries (.so) files need to present (or specified) at link time? 共享库(.so)文件是否需要在链接时显示(或指定)?

I've read here ( Difference between shared objects (.so), static libraries (.a), and DLL's (.so)? ) that .so files must be present at compile time, but in my experience this is not true? 我在这里已经读到了( 共享对象(.so),静态库(.a)和DLL(.so)之间的区别? ),. so文件必须在编译时出现,但是根据我的经验,这不是真的吗?

Doesn't shared libraries just get linked at runtime using dlopen and dlsym , so that the library may not be present on the system, when the application is linked? 共享库不是仅在运行时使用dlopendlsym ,这样在链接应用程序时该库可能不会出现在系统上吗?

Most shared libraries need to be present both at build time and at run time. 大多数共享库都需要在构建时和运行时都存在。 Notice that shared libraries are not DLL s (which is a Windows thing). 请注意,共享库不是 DLL (这是Windows的东西)。

I assume you code for Linux. 我假设您为Linux编写代码。 Details are different on other OSes (and they matter). 其他操作系统的详细信息有所不同(并且很重要)。

For example, if you are compiling a Qt application, you need the Qt shared libraries (such as /usr/lib/x86_64-linux-gnu/libQt5Gui.so and many others) both when building your application and when running it. 例如,如果您正在编译Qt应用程序,则在构建应用程序和运行它时都需要Qt共享库(例如/usr/lib/x86_64-linux-gnu/libQt5Gui.so等)。 Read about the dynamic linker ld-linux.so(8) & about ELF . 阅读有关动态链接器ld-linux.so(8)ELF的信息

But you are asking about dynamic loading (using dlopen(3) with dlsym(3) ...) of plugins . 但是您正在询问插件的 动态加载 (将dlopen(3)dlsym(3)一起使用 )。 Then read Levine's Linkers & Loaders , Program Library HowTo , C++ dlopen mini HowTo , and Drepper's How To Write Shared Libraries 然后阅读Levine的链接器和加载器程序库HowToC ++ dlopen mini HowTo和Drepper的如何编写共享库的方法

See also this answer . 另请参阅此答案

Some libraries and frameworks try to abstract the loading of plugins in an OS-neutral manner. 一些库和框架尝试以与操作系统无关的方式抽象化插件的加载。 Read eg about Qt plugins support, or about POCO shared libraries (poorly named, it is about plugins). 阅读有关Qt插件支持或POCO共享库的信息 (俗称的是关于插件)。

You can have it both way, it all works. 您可以同时使用它,所有方法都可以。

While with library present at compile time,instead of get library by dlopen/LoadLibrary explictly, you can use all the functions directly 当库在编译时出现时,而不是通过dlopen / LoadLibrary显式获取库,您可以直接使用所有功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM