如何在OS X中包含omp.h? [英] How to include omp.h in OS X?

查看:2130
本文介绍了如何在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 ,所以我搜索它,发现了几个 omp.h gcc-4.9.1 / build / 下的文件夹。

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)

感谢阅读。

推荐答案

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将Clang可执行文件与类似GCC的名称进行符号链接。我个人发现,自从最近的Clang版本附带Xcode的反应对无法识别的命令行选项(例如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.

这篇关于如何在OS X中包含omp.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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