
标签:
/tmp/ccM2tvqF.o: In function `main:
thread_c.c:(.text+0x1f): undefined reference to `pthread_create

thread_c.c:(.text+0x52): undefined reference to `pthread_create
thread_c.c:(.text+0x7d): undefined reference to `pthread_join
thread_c.c:(.text+0xa9): undefined reference to `pthread_join

collect2: ld returned 1 exit status
查了老半天,以为代码的问题,最后才知道是因为pthread库不是Linux系统默认的库,连接时需要使用库libpthread.a,所以在使用pthread_create创建线程时,在编译中要加-lpthread参数:gcc test_thread.c -lpthread -o test_thread. 加上这个以后编译成功!
c++使用thread类时编译出错,对‘pthread_create’未定义的引用
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-69595-1.html
哎呀杨洋啊
我们私了