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

Jam*_*sev 1 c++ osx-mountain-lion

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

  PATH=${PATH}:/Applications/Xcode.app/Contents/Developer/usr/bin:${PATH}
Run Code Online (Sandbox Code Playgroud)

找到编译器

[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
Run Code Online (Sandbox Code Playgroud)

Hello world看起来如下

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

无法从命令行和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
Run Code Online (Sandbox Code Playgroud)

在我的道路上我还应该拥有什么?

Jam*_*sev 7

答案是,一如既往,显而易见

安装Xcode命令行工具

在此输入图像描述

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

在此输入图像描述

再试一次..一切都在自动化

从侧面说明,从OSX10.7升级到OSX10.8是很奇怪的,删除了这些链接