“严重错误:未找到'omp.h'文件"在Apple M1上使用c [英] "fatal error: 'omp.h' file not found" using clang on Apple M1

查看:232
本文介绍了“严重错误:未找到'omp.h'文件"在Apple M1上使用c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Clang都无法找到 omp.h .这就是我想要做的

Clang isn't able to find omp.h whenever I try to compile with openMP flag. Here's what I'm trying to do

clang++ -dynamiclib -I/opt/homebrew/Cellar/eigen/3.3.9/include/eigen3/ -Xpreprocessor -fopenmp -o libfoo.dylib foolibrary.cpp -lomp

尽管我在/opt/homebrew/Cellar/libomp/11.0.1/include/omp.h 中有omp.h,而clang在 usr/bin/clang .我需要配置什么以便它能够找到它吗?

Although I have omp.h in /opt/homebrew/Cellar/libomp/11.0.1/include/omp.h, while clang is in usr/bin/clang. Is there anything I need to configure so that it's able to find it?

推荐答案

在使用brew作为本地目标M1时,在/usr/bin not >.酿造说明显示其首选位置是/opt/homebrew ./usr/bin中的clang是指向Apple命令行工具的链接.您可以使用 -v 看到它.

When using brew to target the M1 natively, the brew installed clang is not in /usr/bin. The brew instructions show that the preferred location for it is /opt/homebrew. The clang in /usr/bin is a link to the Apple command line tools one; you can see that by using -v.

$ /usr/bin/clang -v
/usr/bin/clang -v
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

要安装Brew罐,您需要按照brew安装时给您的说明进行操作:-

To get the brew installed clang you need to follow the instructions brew gave you when you installed it :-

llvm is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.profile

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"

这样做可以解决包含问题,但是,至少对我来说,不是解决链接问题的库.

Doing that resolves the include issue, but, at least for me, not the library linking one.

/opt/homebrew/opt/llvm/bin/clang -v -fopenmp hello_omp.c
clang version 11.1.0
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
 "/opt/homebrew/Cellar/llvm/11.1.0/bin/clang-11" -cc1 -triple arm64-apple-macosx11.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello_omp.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu apple-a7 -target-feature +fp-armv8 -target-feature +neon -target-feature +crypto -target-feature +zcm -target-feature +zcz -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -fdebug-compilation-dir /Users/jcownie/tmp -ferror-limit 19 -fmessage-length=163 -fopenmp -fopenmp-cuda-parallel-target-regions -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -o /var/folders/lt/nf3dtk8j16qfsl97d_vgv4dw000lts/T/hello_omp-bd4ce3.o -x c hello_omp.c
clang -cc1 version 11.1.0 based upon LLVM 11.1.0 default target arm64-apple-darwin20.3.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /opt/homebrew/Cellar/llvm/11.1.0/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 11.0.0 0.0.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o a.out /var/folders/lt/nf3dtk8j16qfsl97d_vgv4dw000lts/T/hello_omp-bd4ce3.o -lomp -lSystem /opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0/lib/darwin/libclang_rt.osx.a
ld: library not found for -lomp
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

如果你明确地传递推荐的$LDFLAGS,那么事情就可以了...

If you explicitly pass the recommended $LDFLAGS, then things work...

$ echo $LDFLAGS
-L/opt/homebrew/opt/llvm/lib
$ /opt/homebrew/opt/llvm/bin/clang $LDFLAGS -fopenmp hello_omp.c
/opt/homebrew/opt/llvm/bin/clang $LDFLAGS -fopenmp hello_omp.c
$ ./a.out
./a.out
Hello from thread 0
Hello from thread 5
Hello from thread 4
Hello from thread 1
Hello from thread 3
Hello from thread 2
Hello from thread 7
Hello from thread 6
$ 

我的解决方案(很强悍,但确实可行)是创建自己的shell脚本,以使用适当的库路径来调用编译器.您可以在如何构建LLVM(clang,clang ++)用于Apple M1?

My (hacky, but it works) solution to that has been to create my own shell scripts to invoke the compilers with the appropriate library path; you can see this hack in How to build LLVM (clang,clang++) for Apple M1?

还有一点要提防的是,目前以M1为目标时,LLVM中似乎对OpenMP任务的支持被打破了.(请参见"在将第一私有参数传递给Apple M1上的任务时崩溃";).

One more point to beware of is that the support for OpenMP tasks seems to be broken in LLVM when targeting the M1 at present. (See "Crash in passing firstprivate args to tasks on Apple M1").

这篇关于“严重错误:未找到'omp.h'文件"在Apple M1上使用c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆