OSX10.8上的C ++ Hello World问题

时间:2012-08-05 16:42:25

标签: c++ osx-mountain-lion

我的个人资料已更新,以指出我认为正确的位置:

  PATH=${PATH}:/Applications/Xcode.app/Contents/Developer/usr/bin:${PATH}

找到编译器

[11:39:32] ~: $ which g++
/Applications/Xcode.app/Contents/Developer/usr/bin//g++
[11:39:35] ~: $ which gcc
/Applications/Xcode.app/Contents/Developer/usr/bin//gcc

Hello world看起来如下

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

无法从命令行和带有

的TextMate执行
[11:40:15] Desktop: $ g++ untitled.cpp 
untitled.cpp:1:20: error: iostream: No such file or directory
untitled.cpp: In function ‘int main()’:
untitled.cpp:6: error: ‘cout’ was not declared in this scope

我的道路上还有什么其他的东西可以丢失吗?

2 个答案:

答案 0 :(得分:7)

答案一如既往,显而易见

安装Xcode命令行工具

enter image description here

检查您的/usr/bin并找到:

enter image description here

再试一次..一切都是自动运作

另一方面,从OSX10.7升级到OSX10.8,删除这些链接很奇怪

答案 1 :(得分:-2)

这个答案适用于GCC,但其他非vcc编译器可能是相同的。当我使用GCC时,iostream不存在,但iostream.h是,我建议你尝试iostream.h,如果再次使用STL标题遇到这个问题,请添加.h。