# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <omp.h>
using namespace std;
int main ( int argc, char *argv[] );
//********************************
int main ( int argc, char *argv[] )
//**********************************
{
int id;
double wtime;
cout << "\n";
cout << "HELLO_OPENMP\n";
cout << " C++/OpenMP version\n";
cout << "\n";
cout << " Number of processors available = " << omp_get_num_procs ( ) << "\n";
cout << " Number of threads = " << omp_get_max_threads ( ) << "\n";
wtime = omp_get_wtime ( );
# pragma omp parallel \
private ( id )
{
id = omp_get_thread_num ( );
cout << " This is process " << id << "\n";
}
wtime = omp_get_wtime ( ) - wtime;
cout << "\n";
cout << "HELLO_OPENMP\n";
cout << " Normal end of execution.\n";
cout << "\n";
cout << " Elapsed wall clock time = " << wtime << "\n";
return 0;
}
字符串
你好,我试着运行这个程序:
我运行make“文件名”,我有这个错误:
g++ hello_openmp.cpp -o hello_openmp /tmp/ccz80Tfg.o:In function main': hello_openmp.cpp:(.text+0x4d): undefined reference to
omp_get_num_procs' hello_openmp.cpp:(.text+0x7a):undefined reference to omp_get_max_threads' hello_openmp.cpp:(.text+0xa7): undefined reference to
omp_get_wtime' hello_openmp.cpp:(.text+0xb9):undefined reference to omp_get_thread_num' hello_openmp.cpp:(.text+0xea): undefined reference to
omp_get_wtime' collect2:error:ld returned 1 exit status make:* [hello_openmp] Error 1
有谁知道这个错误是什么意思。对不起,我是C++的初学者。谢谢
2条答案
按热度按时间rryofs0p1#
您需要将标记**-fopenmp**添加到编译标记中。
yfwxisqw2#
如果您使用的是CMakeLists.txt,请尝试添加以下内容,
字符串