gpt4 book ai didi

linux - linux 包管理器安装的库是静态链接还是动态链接?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:37:50 25 4
gpt4 key购买 nike

如果cryptopp例如使用 sudo apt install libcrypto++-dev 安装然后包括使用 #include <cryptopp/base64.h> , 这个库是静态链接还是动态链接?

CMakeLists.txt 包括 cryptopptarget_link_libraries .

最佳答案

will [a library installed via a package manager] be statically or dynamically linked?

这取决于几个因素。首先,两个库都必须可用。对于 Unix 和 Linux 上的 Crypto++,静态库和动态库都可用。在 Windows 上,仅提供静态库。

其次,假设两个库都可用,链接器的配置很重要。在 Linux 上使用 ld , 动态库总是默认使用。在 OS X 上,默认情况下也始终使用动态库。在 Windows 上,链接器配置不会影响因素,因为选项控制它。

第三,它取决于链接器选项。在 Windows 上 - 如果动态库可用 - 这将取决于您链接到的库。它可以是动态链接库的导入库上的静态。在 Linux 上使用 ld您可以使用 :filename 链接到静态库:

-l namespec

--library=namespec

Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.

On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a .so extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.

The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

最后,使用 CMake 时,行为并不是一件简单的事情。默认行为可能是不添加任何内容。将 -lcryptopp-l:cryptopp 添加到您的 LDFLAGSLDLIBS 将无效,因为 CMake 不接受习惯旗帜。您必须手动将库添加到每个目标。

关于linux - linux 包管理器安装的库是静态链接还是动态链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46508524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com