开发者

gcc command line on Mac OS X with XCode 2.5

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 << "hell开发者_运维百科o, 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


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)


This works:

#include <iostream>
using namespace std;

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜