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

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

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest