Installing Clang 10 on Docker container

Mehmet Ali Baykara
2 min readApr 13, 2020

--

LLVM

Currently runs much application on a cloud-based environment. Through CI/CD, the development process is also part of the production. Thus lead to the developers to make their development environment cloud-native. The cloud-native environment became an essential part of software lifecycle. Also, C/C++ developers are using docker container for development. Therefore in this post, I will install clang 10 on the docker container. Clang 10 supports many C++ 20 features.

So now Clang 10 is released and prebuilt binaries are available on the official LLVM website. Here is the corresponding link.

Clang is beside GCC one of the powerful C/C++ compiler, which also natively supports cross-compiling for different architectures. LLVM also provides different tools such as clang-tidy etc. to see more. We will focus on how to install clang 10 on the docker container.

Now let’s start to install the new version of clang which is 10, on docker. Firstly we are going to start with creating our custom dockerfile. I will use ubuntu 18.04 as the base image. The Dockerfile looks as below

#we are using ubuntu base image
FROM ubuntu:18.04
# installing requirements to get and extract prebuilt binaries
RUN apt-get update && apt-get install -y \
xz-utils \
curl \
&& rm -rf /var/lib/apt/lists/*
#Getting prebuilt binary from llvm
RUN curl -SL https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
| tar -xJC . && \
mv clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04 clang_10 && \
echo ‘export PATH=/clang_10/bin:$PATH’ >> ~/.bashrc && \
echo ‘export LD_LIBRARY_PATH=/clang_10/lib:$LD_LIBRARY_PATH’ >> ~/.bashrc
#start the container from bash
CMD [ “/bin/bash” ]

If you want to use Debian-buster as a base image you have to install dependency below as well.

RUN apt-get update && apt-get install -y libncurses5

Now we can hit the terminal to build our image

$ docker build -t clang_10 .

It will take a few minutes. It is a relatively big image with over 2 GB. When the image build process is done. Let’s start our container and verify the compiler.

$ docker run --rm -it clang_10 

Briefly explain the docker command

docker run  --> basic start container command
--rm --> remove the container after job done
-it --> to interact with container
clang_10 --> the image name

Now you have to be in the container. Simply check whether clang 10 is installed by hitting the following command

root@54dfgd54rh:/# clang --version
clang version 10.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /clang_10/bin

That’s it! you are ready to use the latest and greatest version of clang on docker container :) Happy Hacking

Resources
* releases.llvm.org
* solarianprogrammer.com
* Thanks to Gökhan Topcu for review
* https://de.wikipedia.org/wiki/Clang

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Mehmet Ali Baykara
Mehmet Ali Baykara

Written by Mehmet Ali Baykara

Don't buy me a coffee! Just Say "Hi"

No responses yet

Write a response