Windows下MinGW编译openmp程序失败

      最近在看OpenMP相关内容,选择了gcc的实现版本,出于方便考虑在windows下用MinGW装了gcc, 但是在编译openmp测试程序的时候编译失败了,openmp测试程序如下:

#include
int main()
{
    #pragma omp parallel
    {
        std::cout << "Hello World!\n"; 
    }
    return 0;
}

编译报错

C:/mingw/bin/…/lib/gcc/mingw32/6.3.0/…/…/…/…/mingw32/bin/ld.exe: cannot find -lpthread collect2.exe: error: ld returned 1 exit status

上网搜了一下,发现gcc的实现用到了pthread库,但是MinGW没有默认安装pthread,打开MinGW Installation Manager,发现确实没有安装pthread库。

解决方法:

  • 打开MinGW Installation Manager安装pthread库,选择mark for installation;
  • 菜单栏->Installation->Apply changes;

pthread的相关库为:
pthread库

你可能感兴趣的:(coding,problem)