Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP Mac OSX Lion c++ linker error Undefined symbols for architecture x86_64: "_omp_get_thread_num"

I cannot find this question anywhere on the internet. So my linker error is: Undefined symbols for architecture x86_64: "_omp_get_thread_num()"

This is my code:

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);
    }
}
like image 683
Guybrush Threepwood Avatar asked Sep 19 '12 18:09

Guybrush Threepwood


2 Answers

Looks you forgot to use the -fopenmp flag to tell the compiler you want to use openmp, your example compiles fine as g++ test.cpp -fopenmp -o test on mac osx lion

like image 188
pyCthon Avatar answered Nov 15 '22 00:11

pyCthon


It is hard to diagnose such a problem. I guess the linker cannot find the library. Add libgomp to you linker libraries.

You have to link library, to get object.

Simular problem here:

http://www.eclipse.org/forums/index.php/m/901477/

and more more over the internet. Reason is not linked library.

you can do it by adding: -fopenmp

in GCC.

like image 33
CyberGuy Avatar answered Nov 14 '22 23:11

CyberGuy