对‘sem_init’未定义的引用

编译出错:

对‘sem_init’未定义的引用

原因:

一般出错的原因是没有链接库导致的

解决方法:

在编译最后添加 -lpthread

例如:

gcc -o test test.c -lpthread

/tmp/ccLlGqr2.o:在函数‘read_func1’中: tempCodeRunnerFile.c:(.text+0x6e):对‘sem_wait’未定义引用 tempCodeRunnerFile.c:(.text+0x93):对‘sem_post’未定义引用 tempCodeRunnerFile.c:(.text+0x9d):对‘sem_post’未定义引用 /tmp/ccLlGqr2.o:在函数‘read_func2’中: tempCodeRunnerFile.c:(.text+0xe2):对‘sem_wait’未定义引用 tempCodeRunnerFile.c:(.text+0x107):对‘sem_post’未定义引用 tempCodeRunnerFile.c:(.text+0x111):对‘sem_post’未定义引用 /tmp/ccLlGqr2.o:在函数‘write_func’中: tempCodeRunnerFile.c:(.text+0x176):对‘sem_wait’未定义引用 tempCodeRunnerFile.c:(.text+0x180):对‘sem_wait’未定义引用 tempCodeRunnerFile.c:(.text+0x1bf):对‘sem_post’未定义引用 /tmp/ccLlGqr2.o:在函数‘main’中: tempCodeRunnerFile.c:(.text+0x226):对‘sem_init未定义引用 tempCodeRunnerFile.c:(.text+0x23a):对‘sem_init未定义引用 tempCodeRunnerFile.c:(.text+0x255):对‘pthread_create’未定义引用 tempCodeRunnerFile.c:(.text+0x270):对‘pthread_create’未定义引用 tempCodeRunnerFile.c:(.text+0x28b):对‘pthread_create’未定义引用 tempCodeRunnerFile.c:(.text+0x29c):对‘pthread_join’未定义引用 tempCodeRunnerFile.c:(.text+0x2ad):对‘pthread_join’未定义引用 tempCodeRunnerFile.c:(.text+0x2be):对‘pthread_join’未定义引用 tempCodeRunnerFile.c:(.text+0x2c8):对‘sem_destroy’未定义引用 tempCodeRunnerFile.c:(.text+0x2d2):对‘sem_destroy’未定义引用 collect2: erro r: ld returned 1 exit status
06-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值