title: Ubuntu 18.04 setup clang++
body: <p>How do I properly setup clang to use c++ std library on Ubuntu 18.04?
  I have installed a bunch of libraries suggested in other threads
  but without success. I also have two gcc compilers (7,9) installed and I make
  use of update-alternative to switch between them. Also Clang-6, Clang-9 and llvm-9
  are installed.</p>
  <p>Some libraries I installed</p>
  <pre><code>sudo apt install libstdc++-9-dev
  sudo apt install libc++-9-dev
  sudo apt install g++-7-multilib  
  sudo apt install g++-9-multilib
  </code></pre>
  <p>I think there more but the result stayed the same.</p>
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      std::cout &lt;&lt; &quot;Hello World\n&quot;;
  }  
  </code></pre>
  <p>Compiling with</p>
  <pre><code>clang++-9 hello_world.cpp
  clang++ hello_world.cpp
  clang++-9 -stdlib=libstdc++ hello_world.cpp
  clang++ -stdlib=libstdc++ hello_world.cpp
  </code></pre>
  <p>All produce</p>
  <pre><code>hello_world.cpp:2:10: fatal error: 'iostream' file not found
  </code></pre>
  <p>I found a bunch of posts on this topic, but most of them were on Windows or macOS
  or 8 years old. There was also <a href="https://gatowololo.github.io/blog/clangmissingheaders/" rel="nofollow noreferrer">this</a> blog post. I am probably missing something
  very obvious and was hoping maybe someone could point me into the right direction.</p>
  <p>I installed clang with the following way, but I don't rember the exact order:</p>
  <pre><code>sudo add-apt-repository ppa:ubuntu-toolchain-r/test
  sudo apt install clang libclang-dev
  sudo apt-get install libclang-9-dev 
  sudo apt-get install clang-9
  sudo apt-get install clang++-9
  
  </code></pre>
  <p>As in the comments suggested tried to compile with
  <code>clang++ -v hello_world.cpp</code> given the following output:</p>
  <pre><code>$ clang++ hello_world.cpp -v 
  clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
  Target: x86_64-pc-linux-gnu
  Thread model: posix
  InstalledDir: /usr/bin
  Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/8
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.5.0
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
  Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
  Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
  Candidate multilib: .;@m64
  Selected multilib: .;@m64
   &quot;/usr/lib/llvm-6.0/bin/clang&quot; -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello_world.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-6.0/lib/clang/6.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/backward -internal-isystem /usr/include/clang/6.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-6.0/lib/clang/6.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /mnt/My_Linux_Files/C++/test2/src -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/hello_world-0f22e3.o -x c++ hello_world.cpp
  clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-pc-linux-gnu
  ignoring nonexistent directory &quot;/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/x86_64-linux-gnu&quot;
  ignoring nonexistent directory &quot;/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/backward&quot;
  ignoring nonexistent directory &quot;/include&quot;
  ignoring duplicate directory &quot;/usr/include/clang/6.0.0/include&quot;
  #include &quot;...&quot; search starts here:
  #include &lt;...&gt; search starts here:
   /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++
   /usr/include/clang/6.0.0/include
   /usr/local/include
   /usr/include/x86_64-linux-gnu
   /usr/include
  End of search list.
  hello_world.cpp:2:10: fatal error: 'iostream' file not found
  #include &lt;iostream&gt;
           ^~~~~~~~~~
  1 error generated.
  </code></pre>
  <p>and with clang++-9:</p>
  <pre><code>$ clang++-9 hello_world.cpp -v 
  clang version 9.0.0-2~ubuntu18.04.2 (tags/RELEASE_900/final)
  Target: x86_64-pc-linux-gnu
  Thread model: posix
  InstalledDir: /usr/bin
  Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/8
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.5.0
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
  Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
  Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
  Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
  Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
  Candidate multilib: .;@m64
  Selected multilib: .;@m64
   &quot;/usr/lib/llvm-9/bin/clang&quot; -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello_world.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-9/lib/clang/9.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /mnt/My_Linux_Files/C++/test2/src -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o /tmp/hello_world-9f4c00.o -x c++ hello_world.cpp
  clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-pc-linux-gnu
  ignoring nonexistent directory &quot;/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/x86_64-linux-gnu&quot;
  ignoring nonexistent directory &quot;/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/backward&quot;
  ignoring nonexistent directory &quot;/include&quot;
  #include &quot;...&quot; search starts here:
  #include &lt;...&gt; search starts here:
   /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++
   /usr/local/include
   /usr/lib/llvm-9/lib/clang/9.0.0/include
   /usr/include/x86_64-linux-gnu
   /usr/include
  End of search list.
  hello_world.cpp:2:10: fatal error: 'iostream' file not found
  #include &lt;iostream&gt;
           ^~~~~~~~~~
  1 error generated.
  </code></pre>
  <p>The line:</p>
  <pre><code>Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
  </code></pre>
  <p>confuses me, does clang think that gcc-10 is installed? Because I don't
  think it is:</p>
  <pre><code>$ find /usr/ -iname &quot;*gcc-10*&quot;
  /usr/share/gcc-10
  /usr/share/doc/gcc-10-base
  /usr/share/doc/libgcc-10-dev
  $
  </code></pre>
  <p><strong>Solution</strong></p>
  <p>As in the comments suggested, installing libstdc++-10 solved my issue</p>