Dur*_*rin 5 c linux gcc dynamic-linking static-linking
1.为什么我们需要链接非标准库/包含非标准头文件,当它们已存在于正确的文件夹中时
anirudh@anirudh-Aspire-5920:~/Documents/DUMP$ locate libpthread
/lib/libpthread-2.12.1.so
/lib/libpthread.so.0
/usr/lib/libpthread.a
/usr/lib/libpthread.so
/usr/lib/libpthread_nonshared.a
/usr/lib/xen/libpthread.a
/usr/lib/xen/libpthread_nonshared.a
anirudh@anirudh-Aspire-5920:
Run Code Online (Sandbox Code Playgroud)
人工页面ld.so/ld-linux.so - dynamic linker/loader说搜索程序所需的必要库In the default path /lib, and then /usr/lib.
当我的库的.so文件已经存在于/ lib文件夹中时,为什么我需要专门链接它.该-l选项还用于链接静态库.但是当我对进程进行pmap时,我发现.so正在使用带有扩展名的pthread动态库,而不是带有扩展名的pthread .a.同样
anirudh@anirudh-Aspire-5920:~/Documents/DUMP$ locate mysql.h
/usr/include/mysql/mysql.h
anirudh@anirudh-Aspire-5920:~/Documents/DUMP$
Run Code Online (Sandbox Code Playgroud)
当它已经存在于/usr/include作为所有头文件的标准文件夹的文件夹中时,为什么我需要使用-I选项专门包含它.
bdo*_*lan 10
/lib和/usr/lib所请求库,这并不意味着它自动加载所有这些库.加载库是一项相当昂贵的操作,因此链接器只加载它知道需要的库.-l是什么告诉它需要图书馆.有一些操作系统和工具链会根据标题中的指令自动尝试找出需要哪些库(Visual C++在Windows上执行此操作),但这种技术并未在Linux上使用.-l用于静态库和共享库.如果两者都存在,则将使用共享版本,除非-static为链接器指定.#include <mysql/mysql.h>,预处理器将寻找/usr/include/mysql/mysql.h它.也就是说,搜索不是递归的 - 如果你指定<mysql.h>预处理器会查看/usr/include/mysql.h但不会 /usr/include/mysql/mysql.h.