Ubuntu下编译程序是出现pthread_create未定义错误

gcc -c node_list.c -o node_list.o
gcc -lpthread sim.o cli.o list.o node_list.o -o sim.exe
sim.o: In function `sim_add_node':
sim.c:(.text+0xa55): undefined reference to `pthread_create'
sim.c:(.text+0xa8a): undefined reference to `pthread_create'
sim.o: In function `sim_kill_nodes':
sim.c:(.text+0xb5a): undefined reference to `pthread_kill'
cli.o: In function `kill_node':
cli.c:(.text+0x4ec): undefined reference to `pthread_kill'
cli.c:(.text+0x512): undefined reference to `pthread_kill'
collect2: ld returned 1 exit status
make: *** [sim.exe] Error 1

百思不得其姐。。。

最后在这里看到了,泪流满面啊。(-l包含库指令的位置要在最后!!)

换了位置之后

gcc sim.o cli.o list.o node_list.o -o sim.exe -lpthread
cp sim.exe ../test/test_sim

可以了。

 

实际上,这可能不是这么简单地将该指令放在最后这么简单。这或许是涉及到lpthread和pthread的用法问题,请参考网友的文章。

http://chaoslawful.iteye.com/blog/568602

转载于:https://www.cnblogs.com/tfanalysis/p/3543219.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值