ubuntu 未定义对“omp_get_num_procs”的引用

yqkkidmi  于 2023-11-17  发布在  其他
关注(0)|答案(2)|浏览(169)
  1. # include <cstdlib>
  2. # include <iostream>
  3. # include <iomanip>
  4. # include <omp.h>
  5. using namespace std;
  6. int main ( int argc, char *argv[] );
  7. //********************************
  8. int main ( int argc, char *argv[] )
  9. //**********************************
  10. {
  11. int id;
  12. double wtime;
  13. cout << "\n";
  14. cout << "HELLO_OPENMP\n";
  15. cout << " C++/OpenMP version\n";
  16. cout << "\n";
  17. cout << " Number of processors available = " << omp_get_num_procs ( ) << "\n";
  18. cout << " Number of threads = " << omp_get_max_threads ( ) << "\n";
  19. wtime = omp_get_wtime ( );
  20. # pragma omp parallel \
  21. private ( id )
  22. {
  23. id = omp_get_thread_num ( );
  24. cout << " This is process " << id << "\n";
  25. }
  26. wtime = omp_get_wtime ( ) - wtime;
  27. cout << "\n";
  28. cout << "HELLO_OPENMP\n";
  29. cout << " Normal end of execution.\n";
  30. cout << "\n";
  31. cout << " Elapsed wall clock time = " << wtime << "\n";
  32. return 0;
  33. }

字符串
你好,我试着运行这个程序:
我运行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++的初学者。谢谢

rryofs0p

rryofs0p1#

您需要将标记**-fopenmp**添加到编译标记中。

yfwxisqw

yfwxisqw2#

如果您使用的是CMakeLists.txt,请尝试添加以下内容,

  1. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -pthread")

字符串

相关问题