Shared library

Posted codingtao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shared library相关的知识,希望对你有一定的参考价值。

There are some differences between shared libraries on linux (*.so), windows (*.dll) and MacOS (*.dylib).

The shared libraries must be located in some folder where they can be found, either by the linker, or by the OS runtime.

It is possible to add the folders of the libraries to the system Path, or copy those shared libraries to some system folder, so they are found by the OS.

In Windows and OSX, the simplest approach is just to copy the shared libraries to the executable folder, so they are found by the executable, without having to modify the path.

In UNIX based operating systems like Linux and OSx, there is something called rpath (run-time search path) that is used to locate the shared libraries that another library or executable needs for execution.

The rpath is encoded inside dynamic libraries and executables and helps the linker to find its required shared libraries.

In linux rpath is just an option, which means that, if the linker doesn’t find the library in rpath, it will continue the search in system defaults paths (LD_LIBRARY_PATH... etc)

But in OSX with dylibs it doesn’t work like that. In OSX, if the linker detects that an rpath is invalid (the file does not exist there), it will fail. In OSX, libraries are built with the hard restriction of knowing (before installing them) where (in which folder) they will be installed.

 

以上是关于Shared library的主要内容,如果未能解决你的问题,请参考以下文章

如何修改shared

llvm中内在的cvta_shared_yes、cvta_shared_yes_64、cvta_to_shared_yes_64等的目的是啥

R热图:将颜色分配给值

C++ 中 make_shared 和普通 shared_ptr 的区别

从另一个 shared_ptr 的原始指针生成 shared_ptr

C++ 智能指针 shared_ptrmake_shared用法