James Raitsev
James Raitsev

Reputation: 96461

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?

Upvotes: 1

Views: 5485

Answers (2)

James Raitsev
James Raitsev

Reputation: 96461

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

Upvotes: 7

user1294021
user1294021

Reputation: 322

This answer is for GCC, but other non-vcc compilers may be the same. When I used GCC iostream was non existent, however iostream.h was, I suggest you try iostream.h and if you run into this problem again with STL headers add the .h.

Upvotes: -2

Related Questions