undefined reference to 'pthread

    xiaoxiao2021-03-25  124

    我们在写pthread线程时,编译时会出现“undefined reference to 'pthread_create”的问题:

    那是因为pthread库不是Linux系统默认的库,链接时需要使用静态库libpthread.a,所以在使用pthread_creat()创建线程,以及调用pthread_atfork()函数建立fork处理程序时,需要链接该库。

    问题解决:

    在编译中要加 -lpthread 参数

    例如:gcc thread.c -o thread -lpthread

    其中thread.c为源文件,要包含头文件pthread.h

    转载请注明原文地址: https://ju.6miu.com/read-11156.html

    最新回复(0)