我正在尝试从以下简单代码段开始学习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?
最佳答案
也将-fopenmp
标志添加到链接器部分。