如何在 OS X 中包含 omp.h?
我是 C 新手,在 OS X 中编译代码时遇到一些问题.
I'm new in C and have some problems compiling my code in OS X.
我在 Eclipse 中编写了很多 Java 代码,并使用终端来编译我的代码.但是现在我正在学习 openMP 并且遇到了麻烦.
I code Java a lot both in Eclipse and use terminal to compile my code. However now I'm learning openMP and have troubles with it.
首先我下载了?? Xcode 来编写 openMP 代码,但它无法识别 <omp.h>
.然后我安装了 g++
.当我在终端中输入 g++ -v
时,我得到了这个:
First I downloaded Xcode to write openMP code but it didn't recognize <omp.h>
. Then I installed g++
. When I type g++ -v
into terminal I get this:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
但是当我使用 g++ Mesh.cpp -fopenmp
我仍然得到
But when I use g++ Mesh.cpp -fopenmp
I still get
Mesh.cpp:4:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
然后我尝试将 PTP 安装到我的 Eclipse 中,但遇到了同样的问题.我以为我的 MacBook 中没有 omp.h
所以我搜索它并在 gcc-4.9.1/build/下的文件夹下找到了几个
omp.h
.
Then I tried to install PTP into my Eclipse and got the same problem.
I thought there was no omp.h
in my MacBook so I searched for it and found several omp.h
under folders under gcc-4.9.1/build/
.
问题来了.根据 Java 经验,我拥有该文件但无法使用它的唯一原因是类路径错误.但是,我不知道如何在 g++、Xcode 或 Eclipse 中更改此配置.但是因为我可以包含像 <stdio.h>
这样的文件并用所有的 IDE 编译它,我怎么不能用 <omp.h>
做同样的事情?
Here comes the problem. Based on the Java experience the only reason why I have the file but cannot use it is that the Class Path is wrong. However, I have no idea how to change this configuration in g++, or in Xcode, or in Eclipse. But since I can include files like <stdio.h>
and compile it with all the IDEs, how can't I do the same with <omp.h>
?
我注意到的另一件事是 gcc 文件夹版本是 4.9.1
,但是当我在终端中输入 gcc -v
时,我在输入 g++ -v
Another thing I noticed is that the gcc folder version is 4.9.1
, but when I type gcc -v
into terminal I get the same with typing in g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
版本信息不应该是关于 4.9.1
的吗?就像 java -version
显示的那样
Shouldn't the version information says something about 4.9.1
? Just like what java -version
shows
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
感谢阅读.任何帮助表示赞赏.
Thanks for reading. Any help is appreciated.
推荐答案
GCC 4.9.1 通常不随 OS X 一起提供(实际上 GCC 不再随 Xcode 一起提供).您的必须是通过其他方式安装的,例如自制程序或自编译,如此处所述.您可能缺少的是正确设置 PATH
变量或额外安装的编译器具有版本后缀的二进制文件,即 gcc-4.9
或 g++-4.9
而不是简单的 gcc
/g++
.
GCC 4.9.1 normally does not ship with OS X (actually no GCC ships with Xcode any more). Yours must have been installed by another means, e.g. Homebrew or self compilation as described here. What you are probably missing is properly set PATH
variable or the additionally installed compiler has version-suffixed binaries, i.e. gcc-4.9
or g++-4.9
instead of simply gcc
/ g++
.
正如@rubenvb 已经提到的,Apple 使用类似 GCC 的名称对 Clang 可执行文件进行符号链接.我个人认为这是一种不好的做法,因为 Xcode 附带的最新 Clang 版本会对无法识别的命令行选项(例如 GCC 前端特定选项)做出反应,并出现硬错误.
As @rubenvb has already mentioned, Apple symlinks the Clang executables with GCC-like names. I personally find that a bad practice since recent Clang versions shipped with Xcode react on unrecognised command-line options (e.g. GCC frontend specific ones) with hard errors.
相关文章