Linux线程编译时,出现以下报错:

undefined reference to 'pthread_create'
undefined reference to 'pthread_join'
collect2: error: ld returned 1 exit status

在这里插入图片描述
问题原因:
这个问题其实是库文件不齐全导致的,pthread 库不是 Linux 系统默认的库,需要在编译时手动链接线程库

解决方法:
gcc test.c -o test -lpthread
gcc test.c -o test -pthread

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐