tags:

views:

614

answers:

4

Hi All,

I am currently running a MacBook Pro with Mac OS X Version 10.5.8. I downloaded XCode version 2.5 and installed it.

Further, I added /XCode2.5/usr/bin to my PATH.

Here is hello.cc program:

#include <iostream>

int main(void)
{
  std::cout << "hello, world" << std:endl;
}

Here is what happens: $> g++ hello.cc

hello.cc: In function ‘int main()’: hello.cc:5: error: ‘cout’ is not a member of ‘std’ hello.cc:5: error: ‘endl’ is not a member of ‘std’

Is setting the PATH not sufficient to run the gcc utilities from the command line on a Mac?

Thanks,

Charlie

A: 

It has been awhile -- as I remember the installation from the Mac OS install DVD (10.4?, 10.5?), two versions of gcc were provided, one for use with XCode, the other for use from the command line. The version for use from the command line installs to /usr/bin. I don't have /XCode2.5/usr/bin on my PATH, and am able to use gcc, etc. I think that you probably want a different download. The version of gcc that is installed to /usr/bin will install libraries in locations that are automatically searched. No modification to PATH or other settings is necessary.

Alternatively, it is easy to install more recent versions of gcc using MacPorts. These are installed in /opt/local/bin, and the PATH must be modified. The MacPorts versions use modified names so that they won't conflict with the standard Apple-supplied version.

M. S. B.
I just checked on my installation of Mac 10.6.2 and the two copies of g++-4.2 and gcc-4.2 are byte for byte identical.
Charles E. Grant
A: 

There is a typo in the code as you've represented it here:

  std::cout << "hello, world" << std:endl;
                                    ^
                                    |
                                  std::endl

However, once I fixed that it seemed to compile and run fine (g++ 4.2.1 installed with XCode on OS X 10.6.2)

Charles E. Grant
It was a typo in the posting not in the code itself.
Charles Reich
A: 

This works:

#include <iostream>
using namespace std;

int main()
{
  cout << "hello, world" << endl;
  return 0;
}
Tom Elliott
A: 

Well after some searching, I found a link to http://connect.apple.com as opposed to (developer.apple.com).

The former site still had a link to XCode 3.1.4 under "Download > Development Tools"

Once I downloaded and installed that (and changed my PATH back to the default), then g++ and gcc work fine.

Thanks all for the quick advice.

Charles Reich