LoginSignup
2
1

docker gcc(g++) and llvm(clang++)

Last updated at Posted at 2018-04-14

gcc(g++)

docker
$ docker pull gcc:latest
latest: Pulling from library/gcc
c73ab1c6897b: Pull complete 
1ab373b3deae: Pull complete 
b542772b4177: Pull complete 
57c8de432dbe: Pull complete 
1785850988c5: Pull complete 
f1e1bd5fd88c: Pull complete 
7d59a64da14a: Pull complete 
ab652ee497ea: Pull complete 
107676f737a8: Pull complete 
Digest: sha256:de65296c868fadefa5f0cb7e24d4fc6e5ab919b82396260993f25fc5fc5a5c24
Status: Downloaded newer image for gcc:latest
$ docker images
REPOSITORY                                              TAG                 IMAGE ID            CREATED             SIZE
gcc                                                     latest              8357b3fcbe41        4 weeks ago         1.64GB
$ docker run --name gcclatest -it  8357b3fcbe41  /bin/bash
gcc
# ls
bin  boot  dev	etc  home  lib	lib64  media  mnt  opt	proc  root  run  sbin  srv  sys  tmp  usr  var
# g++ --version
g++ (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gcc
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

公式GCC(gnu c collection)はdebianのstretchだとわかる。

LLVM(clang++)

ガイドに従って作成予定だった。
A guide to Dockerfiles for building LLVM
https://llvm.org/docs/Docker.html

http://apt.llvm.org
を参考にDebian stretch用にスクリプト作成

llvm6.sh
apt update && apt -y upgrade
apt install -y apt-utils  sudo wget vim
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
echo deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-6.0 main>> /etc/apt/sources.list
echo deb-src http://apt.llvm.org/stretch/ llvm-toolchain-stretch-6.0 main >> /etc/apt/sources.list
apt update
apt install -y clang-6.0 lldb-6.0 lld-6.0 install -y libc++-dev
ln -s /usr/bin/clang++-6.0 /usr/bin/clang++
ln -s /usr/bin/lldb-6.0 /usr/bin/lldb
ln -s /usr/bin/lld-6.0 /usr/bin/lld
# http://apt.llvm.org

両方をコンパイルするスクリプトは

cppall.sh
#!/bin/sh
echo "$ clang++ $1.cpp -std=c++03 -Wall"
clang++ $1.cpp -std=c++03 -lc++ -I/usr/local/include/c++/7.3.0 -I/usr/local/include/c++/7.3.0/x86_64-linux-gnu -Wall -o $1l03
if [  -e $1l03 ]; then
	./$1l03 $2
fi
echo "$ clang++ $1.cpp -lc++ -std=c++11  -Wall"
clang++ $1.cpp -std=c++11 -lc++ -I/usr/local/include/c++/7.3.0 -I/usr/local/include/c++/7.3.0/x86_64-linux-gnu -Wall -o $1l11
if [  -e $1l11 ]; then
	./$1l11 $2
fi
echo "$ clang++ $1.cpp -lc++ -std=c++17  -Wall"
clang++ $1.cpp -std=c++17 -lc++ -I/usr/local/include/c++/7.3.0 -I/usr/local/include/c++/7.3.0/x86_64-linux-gnu -Wall -o $1l17
if [  -e $1l17 ]; then
	./$1l17 $2
fi
echo "\r"
echo "$ g++ $1.cpp -std=c++03  -Wall"
g++ $1.cpp  -std=c++03 -Wall -o $1g03
if [  -e $1g03 ]; then
	./$1g03 $2
fi
echo "\r"
echo "$ g++ $1.cpp -std=c++11  -Wall"
g++ $1.cpp  -std=c++11 -Wall -o $1g11
if [  -e $1g11 ]; then
	./$1g11 $2
fi
echo "\r"
echo "$ g++ $1.cpp -std=c++17  -Wall" 
g++ $1.cpp  -std=c++17 -Wall -o $1g17
if [  -e $1g17 ]; then
	./$1g17 $2
fi

文書履歴(document history)

ver 0.10 初稿GNUのみ 20180404
ver 0.20 LLVM導入 20180501

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

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

Thank you very much for reading to the last sentence.

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

2
1
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
1