Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang doesn't see basic headers

I've tried to compile simple hello world on Fedora 20 with Clang, and I get the following output:

d.cpp:1:10: fatal error: 'iostream' file not found

#include <iostream>

I don't have any idea how to resolve it.

like image 789
sweet_sugar Avatar asked Oct 13 '14 06:10

sweet_sugar


People also ask

Where does Clang look for headers?

Clang searches for them in a directory relative to the location of the clang binary. If you moved the clang binary, you need to move the builtin headers, too.

Does Clang support C ++ 11?

C++11 implementation statusYou can use Clang in C++11 mode with the -std=c++11 option. Clang's C++11 mode can be used with libc++ or with gcc's libstdc++.

Is GCC faster than Clang?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

What is cc1 Clang?

The -cc1 argument indicates that the compiler front-end is to be used, and not the driver. The clang -cc1 functionality implements the core compiler functionality. So, simply speaking. If you do not give -cc1 then you can expect the "look&feel" of standard GCC.


2 Answers

This is because g++ is not installed, so libstdc++ is not present.

You can install g++, or if LLVM is preferred, install LLVM libc++ and specify that you want to use it, like so:

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

You may wish to link /usr/bin/c++ to the default compiler:

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

and then compile simply using

$ c++ <args_as_usual> 
like image 152
ArunasR Avatar answered Oct 14 '22 13:10

ArunasR


Point 3 solved the problem for me.

1. Had the same issue, 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. 
like image 21
user4823890 Avatar answered Oct 14 '22 14:10

user4823890