OpenMP 的 Eclipse 构建配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12727834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse build configuration for OpenMP
提问by clstaudt
I am trying to learn OpenMP, starting with the following simple snippet
我正在尝试学习 OpenMP,从以下简单片段开始
#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.
但是,我想将 Eclipse 与 CDT 一起使用。我创建了一个新的构建配置“OpenMP”,并尝试-fopenmp
在“杂项”下添加标志,从“调试”构建配置中复制其他设置。
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?
所以我想这不是添加 -fopenmp 编译器选项的正确位置吗?我应该使用什么配置来构建 OpenMP?
回答by Raj
Add -fopenmp
flag to the linker section as well.
也将-fopenmp
标志添加到链接器部分。