Eclipse的Eclipse构建配置

时间:2012-10-04 12:58:09

标签: c eclipse build openmp eclipse-cdt

我正在尝试学习OpenMP,从以下简单代码段开始

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

int main(void) {

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

    return 0;
}

只需从命令行编译即可:

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

但是,我想将Eclipse与CDT结合使用。我创建了一个新的构建配置“OpenMP”,并尝试在“Miscellaneous”下添加-fopenmp标志,从“Debug”构建配置中复制其他设置。

enter image description here

构建失败并带有

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

所以我想这不是添加-fopenmp编译器选项的正确位置?我应该使用什么配置来构建OpenMP?

1 个答案:

答案 0 :(得分:12)

也将-fopenmp标志添加到链接器部分。