OpenMP Mac OSX Lion c ++链接器错误体系结构x86_64的未定义符号:“ _ omp_get_thread_num”

Wil*_*ill 4 c++ openmp osx-lion

我在互联网上的任何地方都找不到这个问题。所以我的链接器错误是:体系结构x86_64的未定义符号:“ _omp_get_thread_num()”

这是我的代码:

int nthreads;
int tid;
#pragma omp parallel private(tid)
{
    tid = omp_get_thread_num();
    if (tid == 0) 
    {
        nthreads = omp_get_num_threads();
        printf("number of threads: %d\n", nthreads);
    }
}
Run Code Online (Sandbox Code Playgroud)

pyC*_*hon 5

看起来您忘了使用-fopenmp标志告诉编译器您要使用openmp,您的示例像g++ test.cpp -fopenmp -o test在Mac OSX Lion上一样可以正常编译