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.

 

转载于:https://www.cnblogs.com/codingtao/p/6600334.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值