gcc -lm -lc -lcurl是什么意思

今天学了一下curl库,然后试着去用gcc编译(gcc -c simple.c 和 gcc simple.o -o simple)样例代码发现报以下错误

/usr/bin/ld: simple.o: in function `main':
simple.c:(.text+0xbd): undefined reference to `curl_easy_init'
/usr/bin/ld: simple.c:(.text+0xee): undefined reference to `curl_easy_setopt'
/usr/bin/ld: simple.c:(.text+0x110): undefined reference to `curl_easy_setopt'
/usr/bin/ld: simple.c:(.text+0x126): undefined reference to `curl_easy_perform'
/usr/bin/ld: simple.c:(.text+0x143): undefined reference to `curl_easy_strerror'
/usr/bin/ld: simple.c:(.text+0x16b): undefined reference to `curl_easy_cleanup'
collect2: error: ld returned 1 exit status

原因是我没有加-lcurl参数导致

然后引发思考-lm -lc -lcurl是什么含义:

Linux的库命名是一致的,一般为libxxx.so,或libxxx.a,libxxx.la,那么你要链接某个库就用-lxxx,去掉头lib及"."后面的so,la,a等即可。

例如我编译链接curl的步骤是:

gcc -c simple.c

gcc -lcurl simple.o -o simple,当然你需要用到多个其它库的时候这样:

gcc -lcurl -lm -lc simple.o -o simple

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值