gcc command line on Mac OS X with XCode 2.5

我们两清 提交于 2019-12-11 23:01:32

问题


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


回答1:


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)




回答2:


This works:

#include <iostream>
using namespace std;

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



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/1993835/gcc-command-line-on-mac-os-x-with-xcode-2-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!