linux 包管理器安装的库是静态链接还是动态链接?
Are linux package manager installed libraries statically or dynamically linked?
如果 cryptopp
例如使用 sudo apt install libcrypto++-dev
安装,然后使用 #include <cryptopp/base64.h>
包含,这个库是静态链接还是动态链接?
CMakeLists.txt 在 target_link_libraries
中包含 cryptopp
。
will [a library installed via a package manager] be statically or dynamically linked?
这取决于几个因素。首先,两个库都必须可用。对于 Unix 和 Linux 上的 Crypto++,静态库和动态库都可用。在Windows上,只提供了一个静态库。
其次,假设两个库都可用,linker 的配置很重要。在 Linux 和 ld
上,默认情况下始终使用动态库。在 OS X 上,默认情况下也始终使用动态库。在 Windows 上,linker 配置不考虑因素,因为选项控制它。
第三,这取决于linker选项。在 Windows 上 - 如果动态库可用 - 这将取决于你 link 到的库。对于动态 link 库,它可以是导入库上的静态。在 Linux 和 ld
上,您可以将 :filename
到 link 与静态库一起使用:
-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
到您的 LDFLAGS
或 LDLIBS
将没有效果,因为 CMake 不遵守习惯标志。您必须手动将库添加到每个目标。
如果 cryptopp
例如使用 sudo apt install libcrypto++-dev
安装,然后使用 #include <cryptopp/base64.h>
包含,这个库是静态链接还是动态链接?
CMakeLists.txt 在 target_link_libraries
中包含 cryptopp
。
will [a library installed via a package manager] be statically or dynamically linked?
这取决于几个因素。首先,两个库都必须可用。对于 Unix 和 Linux 上的 Crypto++,静态库和动态库都可用。在Windows上,只提供了一个静态库。
其次,假设两个库都可用,linker 的配置很重要。在 Linux 和 ld
上,默认情况下始终使用动态库。在 OS X 上,默认情况下也始终使用动态库。在 Windows 上,linker 配置不考虑因素,因为选项控制它。
第三,这取决于linker选项。在 Windows 上 - 如果动态库可用 - 这将取决于你 link 到的库。对于动态 link 库,它可以是导入库上的静态。在 Linux 和 ld
上,您可以将 :filename
到 link 与静态库一起使用:
-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
到您的 LDFLAGS
或 LDLIBS
将没有效果,因为 CMake 不遵守习惯标志。您必须手动将库添加到每个目标。