gcc -l 选项

50 篇文章 3 订阅

根据官方文档

-llibrary
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)The -l option is passed directly to the linker by GCC. Refer to your linker documentation for exact details. The general description below applies to the GNU linker.The linker searches a standard list of directories for the library. The directories searched include several standard system directories plus any that you specify with -L.Static libraries are archives of object files, and have file names like liblibrary.a. Some targets also support shared libraries, which typically have names like liblibrary.so. If both static and shared libraries are found, the linker gives preference to linking with the shared library unless the -static option is used.It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

在使用-l选项时,有以下几点需要注意:

  1. -labc-l abd都可以使用,但第二种方法仅限于支持posix的系统。
  2. 使用-L可以指定链接库的搜索路径。
  3. 如果同时搜索到静态库、动态库,优先使用动态库。除非使用了-static选项。
  4. 链接器会按照指定的顺序加载依赖库或二进制文件,所以要确认被依赖项在源文件的后面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值