Skip to content

Instantly share code, notes, and snippets.

@shahin-you
Created February 23, 2025 23:33
Show Gist options
  • Save shahin-you/e89a8c38fe0f9131abd21b07c9142f21 to your computer and use it in GitHub Desktop.
Save shahin-you/e89a8c38fe0f9131abd21b07c9142f21 to your computer and use it in GitHub Desktop.
Docker file for C++ build environment using GCC/G++
# Use Ubuntu 24.04 as the base image
FROM ubuntu:24.04
# Avoid interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive
LABEL Version="1.0.0"
LABEL Description="Complete C++ Build Environment with GCC 13.3.0"
ENV HOME=/root
USER root
# Install required packages: build tools, GCC/G++ 13, make, gdb, cmake, and git
RUN apt-get update && apt-get install -y \
build-essential \
ca-certificates \
gcc-13 \
g++-13 \
make \
gdb \
curl \
cmake \
git \
libxml2 \
libgtest-dev \
&& rm -rf /var/lib/apt/lists/*
# Set gcc/g++ alternatives to make gcc-13 and g++-13 the default compilers
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100
#install gtest
RUN apt-get update && apt-get install -y libgtest-dev cmake && \
mkdir -p /tmp/build && \
cd /tmp/build && \
cmake /usr/src/googletest/googletest && \
make && \
cp lib/libgtest*.a /usr/lib/ && \
cd / && rm -rf /tmp/build && \
mkdir -p /usr/local/lib/googletest && \
ln -s /usr/lib/libgtest.a /usr/local/lib/googletest/libgtest.a && \
ln -s /usr/lib/libgtest_main.a /usr/local/lib/googletest/libgtest_main.a
# Set the working directory for your project
WORKDIR /workspace
# Default command: launch bash
CMD ["/bin/bash"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment