为什么 clang++ 在 Ubuntu 14.04 上找不到 <iostream>

Why can't clang++ on Ubuntu 14.04 find <iostream>

我正在编译这个程序:

#include <iostream>

int main()
{

}

这个命令

g++ -c hello_world.cpp

有效。

这个命令

clang++ -c hello_world.cpp

出现此错误:

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

正在做:

clang++ -c hello_world.cpp -v  

给出:

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.1
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.1
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
 "/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name hello_world.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.24 -v -coverage-file /home/user/code/cpp/Whosebug_questions/hello_world.o -resource-dir /usr/bin/../lib/clang/3.4 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.4/include -internal-externc-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/user/code/cpp/Whosebug_questions -ferror-limit 19 -fmessage-length 202 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o hello_world.o -x c++ hello_world.cpp
clang -cc1 version 3.4 based upon LLVM 3.4 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++
 /usr/local/include
 /usr/bin/../lib/clang/3.4/include
 /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
hello_world.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^
1 error generated.

clang++ 正在谈论使用 gcc 4.9 的东西,但如果我这样做:

g++ --版本

它输出:

g++ --version
g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

这是 iostream 在我机器上的位置:

/usr/share/doc/fp-docs/2.6.2/fcl/iostream
/usr/include/boost/tr1/tr1/iostream
/usr/include/c++/4.8/iostream

尝试安装这些包,

sudo yum groupinstall "Development Tools"
sudo yum install libstdc++-static.x86_64 compat-libstdc++-33.x86_64   

我遇到过这个问题,安装这些包就解决了。

看clang++热衷于使用g++4.9文件,我决定安装g++4.9

ubuntu 没有 4.9 作为正常 "sudo apt-get install g++" 的一部分。他们还在4.8。 (不确定是什么将 gcc 4.9(但显然不是 g++ 4.9)的东西放在我的系统上)。

我发现我可以通过以下方式安装 g++ 4.9:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9

发出这些命令后,clang++ 能够找到