在Mac OS X(Sierra& Mojave)的clang中启用OpenMP支持 [英] Enable OpenMP support in clang in Mac OS X (sierra & Mojave)
问题描述
我使用的是Mac OS X Sierra,我发现clang(LLVM版本8.1.0(clang-802.0.38))不支持OpenMP:
当我运行clang -fopenmp program_name.c
时,出现以下错误:
I am using Mac OS X Sierra, and I found that clang (LLVM version 8.1.0 (clang-802.0.38)) does not support OpenMP:
when I run clang -fopenmp program_name.c
, I got the following error:
clang: error: unsupported option '-fopenmp'
似乎clang不支持-fopenmp
标志.
It seems that clang does not support -fopenmp
flag.
我在自制软件中找不到任何openmp库.根据LLVM网站,LLVM已经支持OpenMP.但是我找不到在编译过程中启用它的方法.
I could not find any openmp library in homebrew. According to LLVM website, LLVM already supports OpenMP. But I could not find a way to enable it during compiling.
这是否意味着Mac中的默认clang不支持OpenMP? 您能提供任何建议吗?
Does this mean that the default clang in Mac does not support OpenMP? Could you provide any suggestions?
(当我切换到GCC来编译相同的程序时(使用brew install gcc --without-multilib
安装了gcc),并且编译成功.)
(When I switch to GCC to compile the same program (gcc is installed using brew install gcc --without-multilib
), and the compilation is successful.)
推荐答案
尝试使用 Homebrew 的llvm:
brew install llvm
然后,您将所有llvm二进制文件保存在/usr/local/opt/llvm/bin
中.例如,要编译 OpenMP Hello World程序,请键入
You then have all the llvm binaries in /usr/local/opt/llvm/bin
. To compile the OpenMP Hello World program, for example, type
/usr/local/opt/llvm/bin/clang -fopenmp -L/usr/local/opt/llvm/lib omp_hello.c -o hello
您可能还必须将CPPFLAGS
设置为-I/usr/local/opt/llvm/include
.
You might also have to set the CPPFLAGS
with -I/usr/local/opt/llvm/include
.
makefile应该如下所示:
A makefile should look like this:
CPP = /usr/local/opt/llvm/bin/clang
CPPFLAGS = -I/usr/local/opt/llvm/include -fopenmp
LDFLAGS = -L/usr/local/opt/llvm/lib
omp_hello: omp_hello.c
$(CPP) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)
更新:在macOS 10.14(Mojave)中,您可能会收到类似
Update: In macOS 10.14 (Mojave) you might get an error like
/usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1/include/omp.h:118:13: fatal error: 'stdlib.h' file not found
如果发生这种情况,/usr/include
中将缺少macOS SDK标头.他们使用 Xcode 10 进入了SDK本身.使用
If this happens, the macOS SDK headers are missing from /usr/include
. They moved into the SDK itself with Xcode 10. Install the headers into /usr/include
with
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
这篇关于在Mac OS X(Sierra& Mojave)的clang中启用OpenMP支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!