LoginSignup
2
0

LLVM: 今日 dockerにclang 導入しました。(解決)docker(141)

Last updated at Posted at 2021-01-02

<この項は書きかけです。順次追記します。>

はじめに

dockerで、gcc/gcc++, clang/clang++, vscode/vscode++を比較できるようにしたかった。

gccとclangは、gcc公式にclangを入れることで解決した。

3つを入れるのは、2019年, 2020年はうまくいかなかった。
2021年になって、落ち着いてやってみたらなんとかなった。

ここではclangを入れるところを書く。
最後に3つをいれたhubのURLを記載する。

課題は、どちらも一つのコンテナになり、更新が大規模になる点。
clangとvscodeを別々のコンテナになるようなdockerfileの記述はこれから。
よい記述がありましたら、ご紹介くださると幸いです。

過去のClangの入ったDockerに、Clangの最新版を導入しようとして失敗。
https://qiita.com/kaizen_nagoya/items/cf6acfa6993f58f66ddb
clang++ docker upgrade

素のubuntuから始めてみた。

途中でディスクが足りないと言われ、ファイルの削除、再起動などをした。

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++

Ubuntu 18.04にaptでLLVM-9をインストール
https://mickey-happygolucky.hatenablog.com/entry/2020/01/06/133319

最後のlnがいることは上記で知った。

VisualCodeも導入した版も作った。

docker:ubuntu に apt でvscodeを導入:
https://qiita.com/kaizen_nagoya/items/8b6023ca43a16c67f3c0

導入時のエラー回避方法。


# 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


途中で出たエラーの解決方法は、下記。

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

docker:ubuntu に apt でvscodeを導入: error while loading shared libraries: libX11-xcb.so.1:
https://qiita.com/kaizen_nagoya/items/8b6023ca43a16c67f3c0

hubへの登録

hubには、次の3つを登録している。利用する場合の方法は下記。

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 初稿 20210102
ver. 0.02 gcc clang vscode 20210103
ver. 0.03 タグ、みだし追記 20210831

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0