最近在看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的相關庫爲: