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

posted @ 2014-02-10 17:06  Merlin-magic  阅读(1064)  评论(0)    收藏  举报