如何使用 openmp 编译 c++?(在 Windows 10 中使用 G++)

How can i compile c++ with openmp? (using g++ in windows 10)

本文关键字:G++ Windows openmp 何使用 编译 c++      更新时间:2023-10-16

我是C++编程的新手。也是openMP中的新功能。 我有这个简单的代码

#include <stdio.h>
#include <omp.h>
int main(int argc, char const *argv[])
{
#pragma omp parallel
printf("This is thread %d out of %dn", omp_get_thread_num(), omp_get_num_threads());
return 0;
}

当我尝试使用

g++ -fopenmp file_name.cpp

在CMD中,我收到此错误

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

我使用Windows 10,gcc版本是6.3.0。 我该如何解决这个问题? 谢谢

对于 MinGW32,这会有所帮助。

或者你可以使用TDM-GCC。您可以下载完整的 TDM-GCC 安装程序,并确保在安装时启用 openmp 支持。软件包也可以,如gcc-5.1.0-tdm64-1-core.zipgcc-5.1.0-tdm64-1-openmp.zip提取到同一文件夹中。