gpt4 book ai didi

c - OpenMP 的 Eclipse 构建配置

转载 作者:太空狗 更新时间:2023-10-29 17:18:31 24 4
gpt4 key购买 nike

我正在尝试学习 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?

最佳答案

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

关于c - OpenMP 的 Eclipse 构建配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12727834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com