C语言多线程编译出现undefined reference to `_imp__pthread_create‘

论坛 期权论坛 脚本     
已经匿名di用户   2022-7-2 22:16   3478   0

原因是没有添加线程库lpthread。

D:\>g++ a.cpp -o a
C:\Users\ADMINI~1\AppData\Local\Temp\ccabskXX.o:a.cpp:(.text+0x60): undefined reference to `_imp__pthread_create'
C:\Users\ADMINI~1\AppData\Local\Temp\ccabskXX.o:a.cpp:(.text+0x7e): undefined reference to `_imp__pthread_join'
c:/dev-cpp5.4.0api/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\ADMINI~1\AppData\Local\Temp\ccabskXX.o: bad reloc address 0x0 in section `.ctors'
collect2.exe: error: ld returned 1 exit status

解决方法:添加编译命令-lpthread

D:\>g++ a.cpp -lpthread -o a

D:\>a
hello world

如果使用的是IDE,例如DEV C++,解决方法:工具-编译选项-编译时加入以下命令:-lpthread。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP