1

我的个人资料已更新以指向我认为正确的位置:

  PATH=${PATH}:/Applications/Xcode.app/Contents/Developer/usr/bin:${PATH}

找到编译器

[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 如下所示

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

无法从命令行和 TextMate 执行

[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

我还应该在我的路上还有什么遗漏?

4

2 回答 2

7

答案一如既往地显而易见

安装 Xcode 命令行工具

在此处输入图像描述

检查您的/usr/bin并在那里找到:

在此处输入图像描述

再试一次..一切都会自动运行

附带说明一下,从 OSX10.7 升级到 OSX10.8 删除了这些链接很奇怪

于 2012-08-05T17:21:12.733 回答
-2

此答案适用于 GCC,但其他非 vcc 编译器可能相同。当我使用 GCC 时,iostream 不存在,但 iostream.h 存在,我建议您尝试 iostream.h,如果您再次遇到此问题,使用 STL 标头添加 .h。

于 2012-08-05T16:54:21.343 回答