Windows下MinGW編譯openmp程序失敗

      最近在看OpenMP相關內容,選擇了gcc的實現版本,出於方便考慮在windows下用MinGW裝了gcc, 但是在編譯openmp測試程序的時候編譯失敗了,openmp測試程序如下:

#include<iostream>
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庫

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章