clang++ fails to compile simple hello world c++ program

After upgrade to 14.04 from 12.04 clang++ stopped working.

$ cat test.cpp
#include <iostream>
int main()
{ std::cout << "Hello World" << std::endl; return 0;
}
$ clang++ test.cpp
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream> ^
1 error generated

Installed with apt-get install clag-3.5 same happened with clang-3.4

Thanks

4

2 Answers

I found to resolve this issue that after installing libstdc++-4.8-dev package, I need to specify the include paths and lib path to the clang++ like this.

clang++ -I/usr/include/c++/4.8/ -I/usr/include/x86_64-linux-gnu/c++/4.8 -L /usr/lib/gcc/x86_64-linux-gnu/4.8 test.cpp -o test
1

Your code works for me. Make sure you have libstdc++-dev installed. It's a virtual package, and in my case (Ubuntu 14.04.2 LTS) having 4.8 works.

sudo apt-get install libstdc++-4.8-dev
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like