Skip to content

Instantly share code, notes, and snippets.

@Guiorgy
Last active December 6, 2025 12:20
Show Gist options
  • Select an option

  • Save Guiorgy/d5b02644873352c7aa9cd90545c2c31a to your computer and use it in GitHub Desktop.

Select an option

Save Guiorgy/d5b02644873352c7aa9cd90545c2c31a to your computer and use it in GitHub Desktop.
Cross-compile a C/C++ project for Linux on a Windows host using Docker
# Copyright © 2025 Guiorgy
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# You can see the full GNU General Public License at
# <https://www.gnu.org/licenses/> for more details.
services:
builder:
container_name: GCC_Builder
user: "${UID:-1000}"
build:
context: .
dockerfile: Dockerfile.builder
args:
UID: "${UID:-1000}"
working_dir: /build
volumes:
- .:/build:rw
command: >
/bin/sh -c '
mkdir -p build &&
cd build &&
cmake ..
'
# Usage: docker compose run --rm builder
# Copyright © 2025 Guiorgy
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# You can see the full GNU General Public License at
# <https://www.gnu.org/licenses/> for more details.
FROM gcc:latest
RUN apt-get -qq update \
&& apt-get -qq upgrade \
# Install dependencies, e.g. OpenSSL
#&& apt-get -qq install \
# libssl-dev \
&& rm -rf /var/lib/apt/lists/*
ARG UID=1000
RUN useradd --non-unique --uid ${UID} --user-group --no-create-home --home /build --shell /sbin/nologin --comment Builder builder \
&& mkdir /build \
&& chown builder:builder /build
USER builder:builder
WORKDIR /build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment