我正在尝试学习 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”并尝试-fopenmp
在“杂项”下添加标志,从“调试”构建配置中复制其他设置。
构建失败
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?