gcc
playground to quickly test new compilers and features.
- build docker container:
./build_docker.sh
- build and run executable:
./run.sh
- update base image of Dockerfile (
FROM gcc:<desired version>
) - re-build docker container
- build and run executable
Download compiler from pre-build compiler-explorer versions and move the extracted folder to
/opt/compiler_explorer/
. E.g.
$ curl -L https://compiler-explorer.s3.amazonaws.com/opt/clang-17.0.1.tar.xz | tar Jx
$ `mkdir /opt/compiler_explorer/`
$ `mv <extracted_compiler> /opt/compiler_explorer/`
Many other compilers are available (e.g. gcc-13.1.0.tar.xz
). A complete list can be obtained as
described here.
If the system doesn't satisfy the GLIBC requirement of the compiler (calling the compiler will
fail), compiling in a docker container might be the best option.
Build binary with complete path to the downloaded compiler and either link to respective standard library, or set library path manually when running the program:
# linking to lib
$ /opt/compiler_explorer/gcc-13.1.0/bin/g++ -std=c++23 -L /opt/compiler_explorer/gcc-13.1.0/lib64 -static main.cpp -o main.out && ./main.out
# set library manually
$ /opt/compiler_explorer/gcc-13.1.0/bin/g++ -std=c++23 main.cpp -o main.out && export LD_LIBRARY_PATH=/opt/compiler_explorer/gcc-13.1.0/lib64/ && ./main.out