Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse build configuration for OpenMP

I am trying to learn OpenMP, starting with the following simple snippet

#include <stdio.h>
#include <stdlib.h>

int main(void) {

    #pragma omp parallel
    printf("Hello OpenMP!\n");

    return 0;
}

Simply compiling from the command line works:

cls ~/Desktop $ gcc -fopenmp HelloOpenMP.c -o HelloOpenMP
cls ~/Desktop $ ./HelloOpenMP 
Hello OpenMP!
Hello OpenMP!

However, I'd like to use Eclipse with CDT. I created a new build configuration "OpenMP" and tried to add the -fopenmp flag under "Miscellaneous", copying the other settings from the "Debug" build configuration.

enter image description here

The build fails with

14:56:16 **** Incremental Build of configuration OpenMP for project HelloOpenMP ****
make all 
Building file: ../src/HelloOpenMP.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -MMD -MP -MF"src/HelloOpenMP.d" -MT"src/HelloOpenMP.d" -o "src/HelloOpenMP.o" "../src/HelloOpenMP.c"
Finished building: ../src/HelloOpenMP.c

Building target: HelloOpenMP
Invoking: MacOS X C Linker
gcc  -o "HelloOpenMP"  ./src/HelloOpenMP.o   
Undefined symbols for architecture x86_64:
  "_GOMP_parallel_end", referenced from:
      _main in HelloOpenMP.o
  "_GOMP_parallel_start", referenced from:
      _main in HelloOpenMP.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [HelloOpenMP] Error 1

So I guess this was not the right place to add the -fopenmp compiler option? What configuration should I use to build with OpenMP?

like image 376
clstaudt Avatar asked Oct 04 '12 12:10

clstaudt


Video Answer


1 Answers

Add -fopenmp flag to the linker section as well.

like image 129
Raj Avatar answered Sep 25 '22 00:09

Raj