views:

384

answers:

2

I'm trying to compile the simplest program on MacOS 10.6 like:

$ g++ -o hello hello.cpp

the following source:

#include <iostream>

int main (int argc, char * const argv[]) {
    std::cout << "Hello, World!\n";
    return 0;
}

I'm getting the error:

hello.cpp:1:20: error: iostream: No such file or directory
hello.cpp: In function ‘int main(int, char* const*)’:
hello.cpp:4: error: ‘cout’ is not a member of ‘std’

So obviously I have to add the include path somewhere. My question is where can I find the include directories and how can add them globally (I don't want to provide the include path whenever I want to compile).

I just installed the XCode 3.1.4 and managed to compile it via Xcode, but not via command line. I found some header files in this directory:

/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers

and tried to add it to the HEADER_SEARCH_PATHS after reading this question, but no luck.

I'm developing on Linux and everything is working fine there, but I want to continue doing that on MacOS. Any help?

+1  A: 

On my Mac, that include file is in /usr/include/c++/4.0.0/iostream . Are you sure you have all the command-line development tools installed? They might not be by default; I'm pretty sure I had to install it manually when I first set up my Mac. There should be a "developer tools" package somewhere on your OS X installation media.

Or, if you want to make sure you're getting the latest version, you can download it from: http://developer.apple.com/technology/xcode.html

Jim Lewis
I have only ppc_intrinsics.h and stdint.h under my /usr/include/gcc/darwin/4.2 folder.
Lipis
Same here (except I have 4.0), but g++ works for me. Do you have a /usr/include/c++ directory?
Jim Lewis
No I don't have it..
Lipis
Sounds like it's not fully installed, then. There should be a "developer tools" package in your OS X installation media, maybe give that a try? I'm pretty sure I had to do this manually when I set up my Mac.
Jim Lewis
After installing the update 3.2.1 for Xcode.. it worked..!!! Thanx..
Lipis
Just edit your answer and tell me to update to the latest version from here http://developer.apple.com/technology/xcode.html and I'll accept this answer :D
Lipis
There you go, glad it worked out for you!
Jim Lewis
Perfect.. I'm glad that it worked out for me too...! ty
Lipis
A: 

$ g++ -o example.bin example.cpp //to compile $ ./example.bin //to run

it's code.

include

using namespace std; int main () { cout << "Hello, World!\n"; return 0; }

adriano