linux下undefined reference to 、`pthread_create‘,undefined reference to `pthread_join‘

linux下undefined reference to 、`pthread_create’,undefined reference to `pthread_join’

源代码:

#include <stdio.h>
#include <assert.h>
#include <pthread.h>

void *mythread(void *arg){
        printf("%s\n", (char*)arg);
        return NULL;
}

int main(int argc, char* argv[]){
        pthread_t p1, p2;
        int rc;
        printf("main:begin\n");
        rc = pthread_create(&p1, NULL, mythread, "A");
        assert(rc == 0);
        rc = pthread_create(&p2, NULL, mythread, "B");
        assert(rc == 0);
        rc = pthread_join(p1, NULL);assert(rc == 0);
        rc = pthread_join(p2, NULL);assert(rc == 0);
        printf("main:end\n");
}
~                  

编译出现的错误:

image-20210314111243345

出现原因:pthread不是linux默认的库,无法找到pthread库中函数的入口地址,会链接失败。

解决方案:

gcc t1.c -o t1 -lpthread
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值