沒有解決方案我在互聯網上找到的解決方案迄今爲止工作。g ++不再找到標準庫OSX 10.6.8
我正在運行OSX 10.6.8。我以前一直在使用gnu編譯器來處理C/C++。我切換到XCode並沒有問題,但我想使用命令行。但是,擦拭我的電腦並從備份恢復後,我得到錯誤bash:g ++命令未找到。
首先,我想我的$ PATH有一點靠不住的,所以我試圖在正確的路徑Path變量增加,現在它承認g ++以及試圖編譯。不過,現在我得到這個錯誤:
hello.cpp:3:20: error: iostream: No such file or directory
hello.cpp: In function ‘int main()’:
hello.cpp:8: error: ‘cout’ is not a member of ‘std’
這裏是世界您好!代碼:已在網上發佈
#include <iostream>
int main()
{
std::cout << "Hello World!";
return 0;
}
解決方案主要被用命名空間和#include語句的問題,但我不認爲這是此時的錯誤。
當我輸入我得到 「其中G ++」 到終端:/開發人員在/ usr/bin中/ G ++ 當我鍵入g ++ -v我得到:
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
4.2.1是一個較舊的版本,所以如果有一件事我可以改變它將切換到我在usr/local/Cellar/gcc中找到的4.7.2。我不確定當我在其他論壇上發現使用自制軟件安裝gcc時,Cellar可能是從哪裏來的。
在此先感謝,這超出了我的肯定。
「我以前一直在用C/C++的gnu編譯器,我改用Xcode」 - 在這裏你搞砸了。回到命令行,真的。 Xcode是廢話。 (哦,+1補償你在Xcode的編程反模式引入的這個問題上浪費的時間。) – 2012-11-12 23:14:48