线程pthread程序编译时库文件的添加-L/usr/lib/-lpthread

编译线程程序时的错误解决:
xjtu129@xjtu129-desktop:~/wz$ gcc testThread.c
/tmp/ccKXccVy.o: In function `main':
testThread.c:(.text+0x2b): undefined reference to `sem_init'
testThread.c:(.text+0x6f): undefined reference to `pthread_create'
testThread.c:(.text+0x9d): undefined reference to `sem_post'
testThread.c:(.text+0xef): undefined reference to `pthread_join'
testThread.c:(.text+0x10a): undefined reference to `sem_destroy'
/tmp/ccKXccVy.o: In function `thread_function':
testThread.c:(.text+0x12a): undefined reference to `sem_wait'
testThread.c:(.text+0x16a): undefined reference to `sem_wait'
collect2: ld 返回 1
这样就可以了:
gcc testThread.c -L/usr/lib/ -lpthread
 

你可能感兴趣的:(JOIN,thread,function,gcc,reference)