1

I've included openmp to my project. I've got -fopenmp in compliler flags.

g++ -std=c++0x -O3 -Wall -c -fmessage-length=0 -march=core2 -fopenmp -ffast-math -fPIC

#pragma omp parallel for for (int i = 0; i < rows; i++) { MatrixXd frame = frames.row(i); output.row(i) = dem(frame); } return output; 

And I have this output when compiling.

hello.cpp:(.text+0x2d88): undefined reference to `omp_get_num_threads' hello.cpp:(.text+0x2d8f): undefined reference to `omp_get_thread_num' ./hello.o: In function `demodulateMatrix': hello.cpp:(.text+0x315f): undefined reference to `GOMP_parallel_start' hello.cpp:(.text+0x316c): undefined reference to `GOMP_parallel_end' 

I've tried to add -fopenmp flag to the linker and I have this output with it

g++: error: unrecognized command line option ‘-fopenmp,’ make: *** [libhello.so] Error 1 

GCC version is 4.8.2 right now.

5
  • Are you using GCC version < 4.2? If so, possible duplicate of help with openmp compilation problems. Try gcc --version. Commented May 21, 2014 at 10:11
  • I've got the latest stable release of gcc. 4.7 or something. Definitely not 4.2 Commented May 21, 2014 at 10:13
  • OK, well it would still be useful to find out exactly what version you have and add it to the question. Commented May 21, 2014 at 10:14
  • What linker are you using? Make sure it’s the right version, and it’s the C++ linker (g++). Clearly compilation does work for you, so GCC correctly recognises the -fopenmp flag. Provide a complete minimal example, along with all command line calls you issue. Commented May 21, 2014 at 10:26
  • I'm using eclipse CDT. The linker is default I guess. Commented May 21, 2014 at 10:27

1 Answer 1

4

You need to pass -fopenmp to the linker as well. It looks like you tried to do that, but you have a syntax error that causes the linker to see -fopenmp, (with a stray comma at the end). Check your makefile.

(Also you seem to pass hello.cpp to the linker instead of hello.o, so your code is compiled twice.)

Sign up to request clarification or add additional context in comments.

2 Comments

Good spot on the ,!
Thanks a lot! Now all working.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.