如何在Windows中使用pthreads?

Cel*_*tas 3 c windows pthreads codeblocks

在尝试编译包含pthreads的代码时,我遇到了诸如下面提到的错误

warning: return type defaults to 'int' [-Wreturn-type]|
|In function 'print_message_function':|
warning: control reaches end of non-void function [-Wreturn-type]|
| undefined reference to `_imp__pthread_create'|
| undefined reference to `_imp__pthread_create'|
| undefined reference to `_imp__pthread_join'|
| undefined reference to `_imp__pthread_join'|
Run Code Online (Sandbox Code Playgroud)

我在Windows 7上运行GCC,但我安装了mingw.我正在使用IDE Code :: Blocks并选择"编译当前文件".这是链接器设置的屏幕截图,我在这里不知所措

codeblocks链接器

更新:我添加-pthread到"其他链接器选项",它更好地工作.还有问题.当我编译它说

|In function 'print_message_function':|
warning: control reaches end of non-void function [-Wreturn-type]|
Run Code Online (Sandbox Code Playgroud)

当我去运行CodeBlocks说"看起来程序尚未构建",当我点击"build"时,我显示此错误

mingw32-g++.exe  -o "SimpleExample.exe" "SimpleExample.o"  -static-libgcc -static-libstdc++ -pthread  
mingw32-g++.exe: error: unrecognized option '-pthread'
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 1 warnings (0 minutes, 0 seconds)
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我想在Windows上构建/测试,但程序在Unix环境下运行.在IDE中编译和构建有什么区别?

小智 7

这个答案来得晚,但......它对我有用,所以我决定分享它.

  1. 我从ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip下载了pthreads库.
  2. 我解压缩它,然后我在
    C:\ ProgramFiles\CodeBlocks\MinGW \包含和C:\ ProgramFiles\CodeBlocks\MinGW\lib中的库文件中复制头文件(.h)
  3. 我将dll文件复制到我项目的可执行文件夹中(myprojects/bin/debug)
  4. 我在
    设置 - >编译器 - >链接器设置 - >我的Code :: Blocks IDE的其他链接器选项中添加了-lpthreadGC2选项

希望这可以提供帮助.