【问题标题】:undefined reference to `omp_get_num_procs'对“omp_get_num_procs”的未定义引用
【发布时间】:2016-06-18 10:36:33
【问题描述】:
# 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 "filename" 并出现此错误:

g++ hello_openmp.cpp -o hello_openmp /tmp/ccz80Tfg.o:在函数main': hello_openmp.cpp:(.text+0x4d): undefined reference toomp_get_num_procs' hello_openmp.cpp:(.text+0x7a): 未定义引用omp_get_max_threads' hello_openmp.cpp:(.text+0xa7): undefined reference toomp_get_wtime' hello_openmp.cpp:(.text+0xb9): 未定义引用omp_get_thread_num' hello_openmp.cpp:(.text+0xea): undefined reference toomp_get_wtime' collect2:错误:ld 返回 1 个退出状态 make: *** [hello_openmp] 错误 1

有谁知道这个错误是什么意思。 对不起,我是 C++ 的初学者。 谢谢

【问题讨论】:

标签: c++ ubuntu


【解决方案1】:

您需要将标志 -fopenmp 添加到您的编译标志中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-14
    • 2015-09-07
    • 2011-03-27
    • 2022-01-22
    • 2016-04-04
    • 2015-11-03
    • 2011-08-11
    • 2019-07-22
    相关资源
    最近更新 更多