17

I have been trying for 3 days to install clang 5.0 on an Ubuntu 16.04 machine. I have tried various guides, but nothing seems to work. When I try to simply grab the latest from SVN and build/install (as detailed here), trying to compile a simple program leads to:

> clang++ basic.cpp
/usr/include/wchar.h:39:11: fatal error: 'stdarg.h' file not found
# include <stdarg.h>

I then tried setting the -DGCC_INSTALL_PREFIX flag for cmake before building, but that leads to the even better error:

> clang++ basic.cpp
fatal error: 'iostream' file not found
#include <iostream>

The steps I've been following are (from the above guide):

> cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ \
-G "Unix Makefiles" path/to/llvm
...
> make
...
> make check-clang
...
> make install-clang
...

Could someone treat me like an idiot and explain step-by-step how to install clang 5.0? Or point me to a guide that even basic fools like me can follow? If you also can explain how to build and install libc++ for C++17, I would be eternally grateful.

Update: It seems I'm not installing clang correctly, since this is the the output of a verbose compilation with clang:

...
#include <...> search starts here:
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include

and this is the output for g++:

#include <...> search starts here:
 /usr/include/c++/5
 /usr/include/x86_64-linux-gnu/c++/5
 /usr/include/c++/5/backward
 /usr/lib/gcc/x86_64-linux-gnu/5/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
...
Steve D
  • 267
  • 1
  • 4
  • 13

1 Answers1

33

Install clang-5 from llvm.org repositores

First, we should add the llvm.org repositories to our sources lists, the line that we should add is:

deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main

Open nano and add the above line to this file:

sudo nano /etc/apt/sources.list.d/llvm.list

Add the repository key, it will make apt able to verify the downloaded packages.

 wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -

After that, update your lists:

sudo apt-get update

Then install clang-5:

sudo apt-get install clang-5.0 lldb-5.0 lld-5.0

It should work.

If you want to get a list of all available packages from this newly added repository:

grep -i package: /var/lib/apt/lists/apt.llvm* | cut -f3 -d: | sort | uniq

It will give you a list like:

clang-5.0 
clang-5.0-doc 
clang-5.0-examples 
libclang-common-5.0-dev
...

You can then install whatever of them you want.


It may help your compile problem

The header file that has been mentioned does not exist in your error: stdarg.h is a part of libstdc++-5-dev package.

I've got this package on my machine, so if I run:

aptitude why libstdc++-5-dev

I will get:

i   build-essential Depends g++ (>= 4:5.2)                            
i A g++             Depends g++-5 (>= 5.3.1-3~)                       
i A g++-5           Depends libstdc++-5-dev (= 5.4.0-6ubuntu1~16.04.4)

So it seems that installing the build-essential package should solve this error of yours, cause I'm not sure what you've done.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Ravexina
  • 54,268
  • 25
  • 157
  • 179
  • I have `build-essential` installed. But the output for my `aptitude why libstdc++-5-dev` is exactly the same as yours, **except** there is no build-essential line. – Steve D Apr 15 '17 at 23:00
  • @SteveD I'm not sure, but maybe it's because part of your stuff are installed from repository and the other part is installed manually, maybe there are some mismatch in libraries version etc. – Ravexina Apr 16 '17 at 07:20
  • I've updated the question body with what I think is the problem, perhaps you know how to fix it? – Steve D Apr 16 '17 at 18:50
  • @SteveD the output are not so helpful in my eyes, maybe someones else find them more helpful. why don't you install it from repositories? I think there is a high chance your problem will go away.. – Ravexina Apr 16 '17 at 19:07
  • I need clang 5.0, which is not available in the repositories. – Steve D Apr 16 '17 at 21:07
  • @SteveD, I updated my answer and added instruction to install clang-5 from official llvm.org repository ;) that would be the best approach to install clang-5 I guess. – Ravexina Apr 18 '17 at 16:36
  • You are an amazing person. This worked! After installing a few more things from that repo, I was able to compile some C++17 code too! To get the latest libc++, I had to follow the guide I linked above, and also the advice in [this question](http://stackoverflow.com/questions/42667275/unable-to-use-libc-with-clang-5-0). Thanks again! – Steve D Apr 19 '17 at 05:37
  • @SteveD, You're welcome and glad that it was helpful ;) – Ravexina Apr 19 '17 at 07:59
  • `libstdc++-5-dev` came down as part of the `clang-5.0` package dependencies. – Mark Ingram Nov 02 '17 at 10:51