问题linker input file unused because linking not done

本文解释了一个常见的GCC编译错误:linker input file unused because linking not done。此错误发生在使用-c选项仅进行编译而不链接的情况下。文章详细说明了如何正确地在不同阶段使用链接标志,并指出应在最终链接可执行文件时才使用这些标志。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

> When I try to compile using the makefile, it gives me the 

> error : 
>>make > gcc -Wall -c client1.c 
> gcc -Wall -c -lsocket -lnsl libfile1.c 
> gcc: -lsocket: linker input file unused because linking not done 
> gcc: -lnsl: linker input file unused because linking not done 
> ar -crvs libshm.a libfile1.o 
> r - libfile1.o > ar: writing libshm.a 
> gcc -Wall client1.o -L. -lshm -o client1  
> Can anybody tell me what the "linker input file unused cus linking not 
> done " error means ??????????  

In the command for this target: libshm.a : libfile1.o     
gcc -Wall -c -lsocket -lnsl libfile1.c  
you're compiling only because you have the -c flag. 
No linking takes place, so gcc is informing you that it is ignoring the -lsocket and -lnsl linker flags. 
You don't need them in that command.  
All of the linking takes place in the command for this target: client1: client1.o libshm.a     
gcc -Wall client1.o -L. -lshm -o client  
Here you will want to use -lsocket and -lnsl because you're linking all of the parts into an executable, 
so you can't leave anything out.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值