Building Clang 9, LLVM 9, libc++ and lldb on Ubuntu 18.04
Posted on January 17, 2013 by Paul
Updated on 24 September 2019
Clang with libc++ represents today a viable alternative to GCC for C and C++ programmers. Even if you plan to ship your C++ application compiled with GCC, I think it is a good test to check your app for errors by building it with a different compiler and library.
In this short post, I’m going to show you how to build the latest Clang and libc++ on a Linux box. I’ve tested this procedure on Ubuntu 18.04, but it should work on Debian and WSL without a problem.
Let’s start by updating your Linux system, open a Terminal and paste the next two lines:
Now, let’s install some additional, but necessary, apps:
Next step, is to get the latest stable versions of Clang, LLVM, libc++ and a few other utilities:
Now, we can build all the above, depending on the speed of your computer, this could take from 30 minutes to a few hours:
In order to be able to use Clang we’ll need to add it to our system path, you can do this with:
Now, let’s download and build lldb:
Next, let’s try to compile a program that uses the C++17 Filesystem:
Save the above file as test_fs.cpp and compile it with:
If you run the resulting executable, you should see a list with all files from the working directory. This is what I see on my machine:
If you want to link your code with the OpenMP library, use the:
If you are interested to learn more about modern C++ I would recommend reading A tour of C++ by Bjarne Stroustrup.