Search code examples
c++osx-mountain-lion

C++ Hello World trouble on OSX10.8


My profile is updated to point to what i think is the right location:

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

Compilers are found

[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 looks as follows

#include <iostream>
using namespace std;

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

Fails to execute both from command line and TextMate with

[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

What else should i have in my path and am missing please?


Solution

  • The answer is, as always, obvious

    Install Xcode Command Line Tools

    enter image description here

    Check your /usr/bin and find there:

    enter image description here

    Try again .. Everything works automagically

    On a side note, it is odd that upgrade from OSX10.7 to OSX10.8 removed these links