对"omp_get_num_procs"的未定义引用
undefined reference to `omp_get_num_procs'
# 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_OPENMPn";
cout << " C++/OpenMP versionn";
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_OPENMPn";
cout << " Normal end of execution.n";
cout << "n";
cout << " Elapsed wall clock time = " << wtime << "n";
return 0;
}
你好我尝试运行这个程序:
我运行"文件名",出现此错误:
G++ hello_openmp.cpp -o hello_openmp/tmp/ccz80Tfg.o:在函数main':
hello_openmp.cpp:(.text+0x4d): undefined reference to
omp_get_num_procs'hello_openmp.cpp:(.text+0x7a):未定义对omp_get_max_threads'
hello_openmp.cpp:(.text+0xa7): undefined reference to
omp_get_wtime的引用hello_openmp.cpp:(.text+0xb9):未定义对omp_get_thread_num'
hello_openmp.cpp:(.text+0xea): undefined reference to
omp_get_wtime的引用collect2:错误:ld 返回 1 个退出状态生成: *** [hello_openmp] 错误 1
有谁知道这个错误的含义是什么。对不起,我是C++初学者。谢谢
您需要将标志 -fopenmp 添加到编译标志中。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用