gpt4 book ai didi

c++ - 如何在 OS X 中包含 omp.h?

转载 作者:IT老高 更新时间:2023-10-28 21:59:33 25 4
gpt4 key购买 nike

我是 C 新手,在 OS X 中编译我的代码时遇到了一些问题。

我在 Eclipse 中编写了很多 Java 代码,并使用终端来编译我的代码。但是现在我正在学习 openMP 并且遇到了麻烦。

首先我下载了​​ Xcode 来编写 openMP 代码,但它无法识别 <omp.h> .然后我安装了g++ .当我输入 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

但是当我使用 g++ Mesh.cpp -fopenmp我还是得到了

Mesh.cpp:4:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.

然后我尝试将 PTP 安装到我的 Eclipse 中并遇到了同样的问题。我以为没有omp.h在我的 MacBook 中,所以我搜索它并找到了几个 omp.hgcc-4.9.1/build/ 下的文件夹下.

问题来了。根据 Java 经验,我拥有该文件但无法使用它的唯一原因是类路径错误。但是,我不知道如何在 g++、Xcode 或 Eclipse 中更改此配置。但是因为我可以包含像 <stdio.h> 这样的文件并用所有的IDE编译它,我怎么不能用<omp.h>做同样的事情? ?

我注意到的另一件事是 gcc 文件夹版本是 4.9.1 ,但是当我输入 gcc -v在终端中输入 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显示

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)

感谢阅读。任何帮助表示赞赏。

最佳答案

这个命令可以帮助你

brew install libomp

brew info libomp
libomp: stable 6.0.1 (bottled)
LLVM's OpenMP runtime library
https://openmp.llvm.org/
/usr/local/Cellar/libomp/6.0.1 (12 files, 1.2MB) *
Poured from bottle on 2018-11-20 at 16:12:22
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/libomp.rb
==> Dependencies
Build: cmake ✘
==> Requirements
Required: macOS >= 10.10 ✔
==> Caveats
On Apple Clang, you need to add several options to use OpenMP's front end
instead of the standard driver option. This usually looks like
-Xpreprocessor -fopenmp -lomp

You might need to make sure the lib and include directories are discoverable
if /usr/local is not searched:

-L/usr/local/opt/libomp/lib -I/usr/local/opt/libomp/include

For CMake, the following flags will cause the OpenMP::OpenMP_CXX target to
be set up correctly:
-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=/usr/local/opt/libomp/lib/libomp.dylib

关于c++ - 如何在 OS X 中包含 omp.h?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25990296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com