编译针对静态或动态库的 C++ 链接
compiling c++ linking against static or dynamic library
当您使用以下命令编译程序时,您链接的是静态库还是动态库?
g++ blink.cpp -o blink -lmraa
其次,这个库是 'installed' 来自使用这些命令的 PPA
sudo add-apt-repository ppa:mraa/mraa
sudo apt-get update
sudo apt-get install libmraa1 libmraa-dev mraa-tools python-mraa python3-mraa
如何判断库是静态的还是动态的?
When you compile a program using the following command, are you linking against a static or dynamic library?
见man ld
:
-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.
Linux是ELF系统。因此,链接器首先搜索 .so
,然后搜索 .a
.
How can you tell if the library is static or dynamic?
两者都有可能,但最有可能 .so
。您需要查看哪些文件包含这些包。
您还可以在生成的可执行文件或共享库上调用 ldd <executable>
并查看它需要哪些共享库。
当您使用以下命令编译程序时,您链接的是静态库还是动态库?
g++ blink.cpp -o blink -lmraa
其次,这个库是 'installed' 来自使用这些命令的 PPA
sudo add-apt-repository ppa:mraa/mraa
sudo apt-get update
sudo apt-get install libmraa1 libmraa-dev mraa-tools python-mraa python3-mraa
如何判断库是静态的还是动态的?
When you compile a program using the following command, are you linking against a static or dynamic library?
见man ld
:
-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.
Linux是ELF系统。因此,链接器首先搜索 .so
,然后搜索 .a
.
How can you tell if the library is static or dynamic?
两者都有可能,但最有可能 .so
。您需要查看哪些文件包含这些包。
您还可以在生成的可执行文件或共享库上调用 ldd <executable>
并查看它需要哪些共享库。