Clang看不到基本标题

问题描述 投票:43回答:4

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

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

#include <iostream>

我不知道如何解决它。

c++ c++11 clang clang++ llvm-clang
4个回答
13
投票

第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.

32
投票

这是因为没有安装g ++,所以libstdc ++不存在。

您可以安装g ++,或者如果首选LLVM,请安装LLVM libc ++并指定您要使用它,如下所示:

sudo apt-get install libc++-dev
clang++ -stdlib=libc++ <rest of arguments>

您可能希望将/ usr / bin / c ++链接到默认编译器:

ln -s /usr/bin/c++ /usr/bin/clang++-libc++

然后简单地使用编译

$ c++ <args_as_usual>

0
投票

看起来你应该使用-stdlib选项提供你的clang构建。 -stdlib = libc ++或-stdlib = libstdc ++之一可能会起作用。有关您的主题的更多详细信息:

When is it necessary to use use the flag -stdlib=libstdc++?


-3
投票

我遇到了这个问题,因为我有一个filename.c,我需要一个filename.cpp。当我告诉它我正在编写C时,显然编译器无法找到C ++头文件!

© www.soinside.com 2019 - 2024. All rights reserved.