C++ Hello World trouble on OSX10.8

前提是你 提交于 2019-12-13 02:23:16

问题


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?


回答1:


The answer is, as always, obvious

Install Xcode Command Line Tools

Check your /usr/bin and find there:

Try again .. Everything works automagically

On a side note, it is odd that upgrade from OSX10.7 to OSX10.8 removed these links




回答2:


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.



来源:https://stackoverflow.com/questions/11818189/c-hello-world-trouble-on-osx10-8

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