【问题标题】:Clang fails to find iostream. What should I do?Clang 找不到 iostream。我该怎么办?
【发布时间】:2015-12-13 22:22:07
【问题描述】:

早些时候,我发了一个related question

我从我的 Mac OS 中的一个大型项目中提取了以下程序

#include <iostream>
int main(){
  std::cout<<"hello"<<std::endl;
  return 0;
}

使用 Clang 编译失败并出现以下错误:

$ clang test.cpp
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^
1 error generated.

有关信息,

A) 我已经使用 xcodeselect --install 安装了 xcode 命令行工具。但似乎 iostream 不在 clang 的默认搜索路径中。

B) 使用 g++ 代替 clang 编译程序。但是在我的问题中,我不允许使用除 clang 之外的其他编译器,或者更改源程序。

C) 我可以看到解决方法,例如,通过调整 .bashrc 中的搜索路径或使用一些符号链接等。但我不愿意使用它们,因为我的 Clang 似乎有安装问题,并且调整路径仅有助于避免这些路径问题之一。

【问题讨论】:

  • @Baum, 101010:请花点时间阅读其他人的问题。

标签: c++ xcode macos iostream


【解决方案1】:

clangclang++ 做不同的事情。如果要编译C++代码,需要使用clang++

或者,您可以通过显式提供语言名称来直接调用 c++ 编译器:

clang -x=c++

【讨论】:

  • 谢谢。我尝试使用 clang++,给出了同样的错误信息。另外,这个程序是第三方项目,编译器是固定的,我不能切换到其他编译器,正如我在问题的(B)中提到的。
  • clang -x=c++ test.cpp 给出“clang-3.7:错误:语言无法识别:'=c++'”。正常吗?
  • @zell。是的,这很正常。输=-x c++
  • 谢谢,但 clang -x c++ test.cpp 或 clang -x=c++ test.cpp 都不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-26
  • 2023-01-05
  • 2016-09-02
  • 1970-01-01
  • 2021-10-01
  • 2013-12-17
相关资源
最近更新 更多