We introduced clang to docker today. (Solution)

Introduction

I wanted to be able to compare gcc/gcc ++, clang/clang ++, vscode/vscode ++ with docker.

gcc and clang were solved by including clang in the gcc formula.

Putting three didn't work in 2019 and 2020. In 2021, I tried calmly and it worked.

Here, write the place to put clang. Finally, enter the URL of the hub with the three.

The problem is that both become one container and the update becomes large-scale. The description of dockerfile that makes clang and vscode into separate containers is yet to be done. If you have a good description, I would appreciate it if you could introduce it.

Attempts to install the latest version of Clang on Docker with past Clang failed. https://qiita.com/kaizen_nagoya/items/cf6acfa6993f58f66ddb clang++ docker upgrade

I started with plain ubuntu.

I was told that there was not enough disk on the way, so I deleted the files and restarted.

bash


$ docker run -it ubuntu /bin/bash

LLVM Debian/Ubuntu nightly packages https://apt.llvm.org/

wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh

ubuntu


# apt update; apt -y upgrade
Get:1 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
                                                                                 
debconf: delaying package configuration, since apt-utils is not installed

debconf: unable to initialize frontend: Dialog

debconf: unable to initialize frontend: Readline

debconf: falling back to frontend: Teletype

 ...
# wget https://apt.llvm.org/llvm.sh

Connecting to apt.llvm.org (apt.llvm.org)|151.101.54.49|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3214 (3.1K) [application/octet-stream]
Saving to: 'llvm.sh'

llvm.sh                      100%[=============================================>]   3.14K  --.-KB/s    in 0.002s  

2021-01-01 14:21:34 (1.83 MB/s) - 'llvm.sh' saved [3214/3214]

# chmod +x llvm.sh
# sudo ./llvm.sh 10
+ needed_binaries=(lsb_release wget add-apt-repository)
+ missing_binaries=()
+ for binary in "${needed_binaries[@]}"
+ which lsb_release
+ missing_binaries+=($binary)
+ for binary in "${needed_binaries[@]}"
+ which wget
+ for binary in "${needed_binaries[@]}"
+ which add-apt-repository
+ missing_binaries+=($binary)
+ [[ 2 -gt 0 ]]
+ echo 'You are missing some tools this script requires: lsb_release' add-apt-repository
You are missing some tools this script requires: lsb_release add-apt-repository
+ echo '(hint: apt install lsb-release wget software-properties-common)'
(hint: apt install lsb-release wget software-properties-common)
+ exit 4
root@11bdf7c39dda:/# apt install lsb-release software-properties-common

...


Setting up libksba8:amd64 (1.3.5-2) ...
Setting up lsb-release (9.20170808ubuntu1) ...
Setting up ucf (3.0038) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) 

# sudo ./llvm.sh 10
+ needed_binaries=(lsb_release wget add-apt-repository)
+ missing_binaries=()
+ for binary in "${needed_binaries[@]}"
+ which lsb_release
+ for binary in "${needed_binaries[@]}"
+ which wget
+ for binary in "${needed_binaries[@]}"
+ which add-apt-repository
+ [[ 0 -gt 0 ]]
+ LLVM_VERSION=11
+ '[' 1 -eq 1 ']'
+ LLVM_VERSION=10
++ lsb_release -is
+ DISTRO=Ubuntu
++ lsb_release -sr
+ VERSION=18.04
+ DIST_VERSION=Ubuntu_18.04
+ [[ 0 -ne 0 ]]
+ declare -A LLVM_VERSION_PATTERNS
+ LLVM_VERSION_PATTERNS[9]=-9
+ LLVM_VERSION_PATTERNS[10]=-10
+ LLVM_VERSION_PATTERNS[11]=-11
+ LLVM_VERSION_PATTERNS[12]=
+ '[' '!' _ ']'
+ LLVM_VERSION_STRING=-10
+ case "$DIST_VERSION" in
+ REPO_NAME='deb http://apt.llvm.org/bionic/   llvm-toolchain-bionic-10  main'
+ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key
+ apt-key add -
--2021-01-01 14:22:38--  https://apt.llvm.org/llvm-snapshot.gpg.key
Resolving apt.llvm.org (apt.llvm.org)... 151.101.54.49, 2a04:4e42:d::561
Connecting to apt.llvm.org (apt.llvm.org)|151.101.54.49|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3145 (3.1K) [application/octet-stream]
Saving to: 'STDOUT'

-                            100%[=============================================>]   3.07K  --.-KB/s    in 0.002s  

2021-01-01 14:22:39 (1.74 MB/s) - written to stdout [3145/3145]

OK
+ add-apt-repository 'deb http://apt.llvm.org/bionic/   llvm-toolchain-bionic-10  main'
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease                                       
Hit:3 http://archive.ubuntu.com/ubuntu bionic InRelease                                                 
Get:1 https://apt.llvm.org/bionic llvm-toolchain-bionic-10 InRelease [5527 B]                  
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                     
Get:5 https://apt.llvm.org/bionic llvm-toolchain-bionic-10/main amd64 Packages [8762 B]
Get:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Fetched 178 kB in 2s (90.3 kB/s) 
Reading package lists... Done
+ apt-get update
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic InRelease                                         
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                       
Hit:1 https://apt.llvm.org/bionic llvm-toolchain-bionic-10 InRelease
Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Fetched 163 kB in 4s (46.1 kB/s)     
Reading package lists... Done
+ apt-get install -y clang-10 lldb-10 lld-10 clangd-10
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  binfmt-support binutils binutils-common binutils-x86-64-linux-gnu gcc-7-base lib32gcc1 lib32stdc++6 libasan4
  libatomic1 libbinutils libc-dev-bin libc6-dev libc6-i386 libcilkrts5 libclang-common-10-dev libclang-cpp10
  libclang1-10 libedit2 libffi-dev libgc1c2 libgcc-7-dev libgomp1 libitm1 liblldb-10 libllvm10 liblsan0 libmpx2
  libobjc-7-dev libobjc4 libomp-10-dev libomp5-10 libpfm4 libpipeline1 libquadmath0 libstdc++-7-dev libtinfo-dev
  libtsan0 libubsan0 libyaml-0-2 libz3-4 libz3-dev linux-libc-dev llvm-10 llvm-10-dev llvm-10-runtime
  llvm-10-tools manpages manpages-dev python3-lldb-10 python3-pkg-resources python3-pygments python3-six
  python3-yaml
Suggested packages:
  binutils-doc clang-10-doc glibc-doc libomp-10-doc libstdc++-7-doc llvm-10-doc man-browser python3-setuptools
  ttf-bitstream-vera
The following NEW packages will be installed:
  binfmt-support binutils binutils-common binutils-x86-64-linux-gnu clang-10 clangd-10 gcc-7-base lib32gcc1
  lib32stdc++6 libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev libc6-i386 libcilkrts5
  libclang-common-10-dev libclang-cpp10 libclang1-10 libedit2 libffi-dev libgc1c2 libgcc-7-dev libgomp1 libitm1
  liblldb-10 libllvm10 liblsan0 libmpx2 libobjc-7-dev libobjc4 libomp-10-dev libomp5-10 libpfm4 libpipeline1
  libquadmath0 libstdc++-7-dev libtinfo-dev libtsan0 libubsan0 libyaml-0-2 libz3-4 libz3-dev linux-libc-dev
  lld-10 lldb-10 llvm-10 llvm-10-dev llvm-10-runtime llvm-10-tools manpages manpages-dev python3-lldb-10
  python3-pkg-resources python3-pygments python3-six python3-yaml
0 upgraded, 57 newly installed, 0 to remove and 0 not upgraded.
Need to get 100 MB of archives.
After this operation, 571 MB of additional disk space will be used.

...

(1:10.0.1~++20201112101950+ef32c611aa2-1~exp1~20201112092551.202) ...
Setting up clangd-10 (1:10.0.1~++20201112101950+ef32c611aa2-1~exp1~20201112092551.202) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ..

$ sudo ln -s -f /usr/bin/clang-10 /usr/bin/clang
$ sudo ln -s -f /usr/bin/clang++-10 /usr/bin/clang++

Install LLVM-9 with apt on Ubuntu 18.04 https://mickey-happygolucky.hatenablog.com/entry/2020/01/06/133319

I learned above that there is a last ln.

I also made a version that introduced Visual Code.

Introducing vscode with apt to docker: ubuntu: https://qiita.com/kaizen_nagoya/items/8b6023ca43a16c67f3c0

How to avoid errors at the time of introduction.


# apt install gconf-service libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 libatk1.0-0 libc6 ca-certificates fonts-liberation lsb-release xdg-utils 

# code --version --user-data-dir /home/cpp
1.52.1
ea3859d4ba2f3e577a159bc91e3074c5d85c0523
x64


The solution to the error that occurred on the way is as follows.

error while loading shared libraries: libX11-xcb.so.1 (solved) https://qiita.com/kaizen_nagoya/items/bc03d5ec280cb622a2d4

Introduce vscode with apt to docker: ubuntu: error while loading shared libraries: libX11-xcb.so.1: https://qiita.com/kaizen_nagoya/items/8b6023ca43a16c67f3c0

Registration to hub

The following three are registered in the hub. The method for using it is as follows.

clang-10>docker run -it kaizenjapan/clang-10 /bin/bash
clang-11>docker run -it kaizenjapan/clang-11 /bin/bash
clang-11 & gcc & visualcode> docker run -it kaizenjapan/gccclang /bin/bash

Document history

ver. 0.01 First draft 20210102 ver. 0.02 gcc clang vscode 20210103

Recommended Posts

We introduced clang to docker today. (Solution)
Introduced vscode with apt to docker: ubuntu
Introduced Docker to Windows 10 Home August 2020 version
clang ++ docker upgrade
I introduced Docker to Rails 6, so I summarized it (beginner)
Why we use Docker
How to install Docker