我是C新手,在編譯我的OS X代碼時遇到了一些問題。如何在OS X中包含omp.h?
我在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,並得到了同樣的問題。 我以爲我的MacBook中沒有omp.h
,所以我搜索了它,發現gcc-4.9.1/build/
下的文件夾下有幾個omp.h
。
問題來了。基於Java的經驗,我有這個文件但不能使用它的唯一原因是類路徑是錯誤的。但是,我不知道如何在g ++,Xcode或Eclipse中更改此配置。但是由於我可以包含像<stdio.h>
這樣的文件,並將其與所有IDE一起編譯,我怎麼能不能和<omp.h>
一樣?
另一件事我注意到的是,海灣合作委員會的文件夾版本是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)
感謝您的閱讀。任何幫助表示讚賞。
我安裝了GCC完全遵循你提到的鏈接,但它仍然無法工作... – user3928256 2014-09-23 08:53:17
如果你按照鏈接頁面上的說明,那麼你的編譯器被命名爲'g ++ - 4.9',除非你安裝到'/ usr/local/bin'中,否則你必須明確地添加路徑。此外,您必須重新配置PTP才能調用'g ++ - 4.9'而不是'g ++'。 – 2014-09-23 08:57:08
謝謝!輸入「export PATH =/usr/gcc-4.9.1/bin:$ PATH」後,我現在可以使用「g ++ - 4.9」。 – user3928256 2014-09-23 09:08:51