xcode 找不到 omp.h,OS X Yosemite 没有使用最新的 gcc 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28546288/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:39:27  来源:igfitidea点击:

omp.h not found, OS X Yosemite not using newest gcc version

xcodegccopenmposx-yosemite

提问by Stephanie Embgen

I am trying to build GraphChi on OS X Yosemite but get the following error:

我正在尝试在 OS X Yosemite 上构建 GraphChi,但出现以下错误:

fatal error: 'omp.h' file not found

fatal error: 'omp.h' file not found

From this question - How to include omp.h in OS X?- I learned that Yosemite uses Clang instead of gcc, which does not include omp.h.

从这个问题 -如何在 OS X 中包含 omp.h?- 我了解到 Yosemite 使用 Clang 而不是 gcc,后者不包括 omp.h。

$ which gcc
/usr/bin/gcc
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

Next, I installed gcc via Homebrew

接下来,我通过 Homebrew 安装了 gcc

$ brew info gcc
gcc: stable 4.9.2 (bottled)
http://gcc.gnu.org
/usr/local/Cellar/gcc/4.9.2_1 (1092 files, 177M)
Built from source with: --without-multilib

and updated $PATHto include the path to the new gcc version

并更新$PATH为包含新 gcc 版本的路径

$ echo $PATH
/usr/local/Cellar/gcc/4.9.2_1:usr/local/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

however, gcc -vand which gccstill point to the old version, and building GraphChi still doesn't work due to the missing omp.h file

然而,gcc -vwhich gcc仍然指向旧版本,并建立GraphChi仍然无法正常工作,由于缺少omp.h文件

Does anyone know what else I need to do?

有谁知道我还需要做什么?

Update

更新

locate omp.hreturned:

locate omp.h回来:

/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/include/omp.h
/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include/omp.h
/usr/local/Cellar/gfortran/4.8.2/gfortran/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include/omp.h

my ~/.profile:

我的~/.profile

export PATH=/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include:/usr/local/Cellar/gcc/4.9.2_1/bin:usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH

回答by shrx

I solved this with installing gccwith homebrew:

gcc用自制软件安装解决了这个问题:

brew install gcc --without-multilib

and then building the source code with

然后构建源代码

CC=gcc-5 CXX=g++-5 cmake ..
CC=gcc-5 CXX=g++-5 make -j7

回答by user2548418

Once you have installed gcc-4.9 with homebrew, it will automatically be in your path. To use OpenMP, you just need to make sure you are using the newly installed gcc-4.9, and it will be able to find omp.h.

使用自制软件安装 gcc-4.9 后,它将自动在您的路径中。要使用 OpenMP,您只需要确保您使用的是新安装的 gcc-4.9,它就能找到 omp.h。

In the case of GraphChi, you will have to go change line 3 of the Makefile to be gcc-4.9. From there, running make should just work. They describe this in their README, but at least the version they describe is out of date https://github.com/GraphChi/graphchi-cpp#problems-compiling-on-mac.

对于 GraphChi,您必须将 Makefile 的第 3 行更改为 gcc-4.9。从那里,运行 make 应该可以正常工作。他们在自述文件中对此进行了描述,但至少他们描述的版本已过时https://github.com/GraphChi/graphchi-cpp#problems-compiling-on-mac

回答by tmlen

clangdoes not support OpenMP yet. Also gccby default links to Apple's LLVM clang compiler (not the GCC installed from brew). Instead gcc-4.9would link to GCC. I think if -fopenmpis specified omp.his included automatically.

clang尚不支持 OpenMP。另外gcc在默认情况下链接到苹果的LLVM编译器铿锵(从酿造安装不GCC)。而是gcc-4.9会链接到 GCC。我认为 if-fopenmpomp.h自动包含的。

It is possible to manually build a version of clang with OpenMP support, see http://clang-omp.github.io

可以手动构建具有 OpenMP 支持的 clang 版本,请参阅http://clang-omp.github.io

回答by tmlen

You shouldn't add the include path to PATH; instead, specify it as CFLAGS, including the -Ioption. You can exportthe CFLAGSvariable, or set it on the fly.

您不应将包含路径添加到PATH; 相反,将其指定为CFLAGS,包括-I选项。您可以export设置CFLAGS变量,或即时设置它。

Depending on how you compile things, you could do

根据你编译的方式,你可以做

CFLAGS=-I/usr/local/Cellar/gcc/4.9.2_1/lib/gcc/4.9/gcc/x86_64-apple-darwin14.1.0/4.9.2/include/omp.h gcc <whatever>

Of course, in this case you can specify it directly on the gcccommand (as -I/usr/local/....), but the CFLAGSvariable also works with configure(as configure often won't have an option to specify where it should look for specific include files); probably with make, or even for those installing a Python package: CFLAGS=-I... pip install <some-package>.

当然,在这种情况下,您可以直接在gcc命令上指定它(as -I/usr/local/....),但该CFLAGS变量也可以使用configure(因为 configure 通常没有选项来指定它应该在哪里查找特定的包含文件);可能带有make,甚至对于那些安装 P​​ython 包的人来说:CFLAGS=-I... pip install <some-package>.

Other flags to consider are

其他要考虑的标志是

  • CXXFLAGS: C++ specific pre-processor flags
  • LDFLAGS: linker specific flags (e.g. LDFLAGS=-L/some/path/...for linking with dynamic libraries).
  • CC: specify the C compiler to use. This is an easy way to avoid the built-in gccalias for clangon OS X. Just use CC=/usr/local/bin/gcc-4 makeor similar.
  • CXX: specify the C++ compiler to use.
  • CXXFLAGS: C++ 特定的预处理器标志
  • LDFLAGS: 链接器特定标志(例如LDFLAGS=-L/some/path/...用于链接动态库)。
  • CC: 指定要使用的 C 编译器。这是避免OS X 上的内置gcc别名的简单方法clang。只需使用CC=/usr/local/bin/gcc-4 make或类似。
  • CXX: 指定要使用的 C++ 编译器。