在CodeBlocks进行多线程编程,需要注意 pthread相关的库,不是默认编译选项。
编译时若遇到error: ld returned 1 exit status
可能是由于未添加pthread
相关的库,则需要设置工程进行添加。
添加方法如下:
- 打开Build options
- 将
pthread
添加进Link libraries
输入pthread
- 重编译一下
编译成功!
补充:如果在终端进行多线程编程,编译时则需要加入-pthread
,如:gcc test.c -o test -pthread
如果不是因未添加pthread
而引起的error: ld returned 1 exit status
可以参考以下文章进行排查。
C语言/c++:实验报错[Error] ld returned 1 exit status的解决方案
[Error] ld returned 1 exit status