Clang 看不到基本标题

新手上路,请多包涵

我尝试使用 Clang 在 Fedora 20 上编译简单的 hello world,得到以下输出:

d.cpp:1:10:致命错误:找不到“iostream”文件

#include <iostream>

我不知道如何解决它。

原文由 sweet_sugar 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 487
2 个回答

第3点 为我解决了这个问题。

1. 有同样的问题,fedora 21::clang 3.5.0:

 clang++ -std=c++14 -pedantic -Wall test_01.cpp -o test_01 -v

2.

 ignoring nonexistent directory "/usr/lib/gcc/i686-redhat-linux/4.9.2/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/bin/../lib/clang/3.5.0/include
 /usr/include
End of search list.
test_01.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>

3.

 sudo yum install gcc-c++

4.

 #include "..." search starts here:
#include <...> search starts here:
 /bin/../lib/gcc/i686-redhat-linux/4.9.2/../../../../include/c++/4.9.2
 /bin/../lib/gcc/i686-redhat-linux/4.9.2/../../../../include/c++/4.9.2/i686-redhat-linux
 /bin/../lib/gcc/i686-redhat-linux/4.9.2/../../../../include/c++/4.9.2/backward
 /usr/local/include
 /usr/bin/../lib/clang/3.5.0/include
 /usr/include
 /usr/lib/gcc/i686-redhat-linux/4.9.2/include
End of search list.

原文由 user4823890 发布,翻译遵循 CC BY-SA 3.0 许可协议

我尝试重新安装命令行工具和“ln”命令,但仍然无法修复。

在尝试了网站上几乎所有其他解决方案之后,仍然无法修复。但是事情会很清楚:编译器试图在 /usr/include 中找到头文件,但是尽管安装了命令行工具,但根本没有这个文件夹。

也许对我们来说最好的直接方法是在这个 IDE 或其他编译器中安装 Xcode 和编码,但不是成本最低的情况。

Mac 内置了 Clang,我们不需要安装额外的编译器。以下是步骤。

我们可以查看 CommandLineToos 文件夹,如果你还没有安装,试试这个命令提前安装。

 xcode-select --install

CommandLineTools 文件夹中,我们可以查看SDK的路由,即 /Library/Developer/CommandLineTools/SDKs

/Library/Developer/CommandLineTools/SDK

我们可以使用 MacOSX.sdk ,对我来说也是 MacOSX12.0.sdk 来查找标题。 C 基本头文件位于 /Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk/usr/include/Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk/usr/include

但它不包含在 C++ 基本头文件中,C++ 基本头文件可以在 /Library/Developer/CommandLineTools/usr/include 找到。我们也可以在终端中使用命令 g++ -v 找到这条路线。

g++ -v

所以解决方案很明显,在终端中输入以下命令。

  1. 打开 bash_profile

打开 ~/.bash_profile

  1. 添加这个。
     export C_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk/usr/include

    export CPLUS_INCLUDE_PATH=/Library/Developer/CommandLineTools/usr/include

  1. 来源它。

源〜/ .bash_profile

此错误将得到修复。

原文由 Zhiheng Yang 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题