I am trying to use this Debian Dockerfile to cross-compile Windows software under Linux using clang-15 and MinGW-w64:
FROM debian:bookworm-20250113
USER root
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
clang-15 \
gcc-12 \
gcc-mingw-w64-x86-64 \
libclang-15-dev \
libclang-cpp15-dev \
llvm-15 \
gcc-12-multilib \
gcc-mingw-w64-i686 \
&& :
RUN mkdir /work
WORKDIR /work
I create /work/hello.c
with this contents:
#include <stdio.h>
int main() {
printf("Hello world\n");
return 0;
}
From within the Docker container, I try to compile it:
clang-15 -v -target x86_64-w64-mingw -o hello.exe ./hello.c
I get the error:
Debian clang version 15.0.6
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: /usr/bin
"/usr/lib/llvm-15/bin/clang" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/work -resource-dir /usr/lib/llvm-15/lib/clang/15.0.6 -internal-isystem /usr/lib/llvm-15/lib/clang/15.0.6/include -internal-isystem /usr/x86_64-w64-mingw32/sys-root/mingw/include -internal-isystem /usr/x86_64-w64-mingw32/include -internal-isystem /usr/x86_64-w64-mingw32/usr/include -internal-isystem /usr/include -fdebug-compilation-dir=/work -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -exception-model=seh -fcolor-diagnostics -faddrsig -o /tmp/hello-c3cd48.o -x c ./hello.c
clang -cc1 version 15.0.6 based upon LLVM 15.0.6 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/x86_64-w64-mingw32/sys-root/mingw/include"
ignoring nonexistent directory "/usr/x86_64-w64-mingw32/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/llvm-15/lib/clang/15.0.6/include
/usr/x86_64-w64-mingw32/include
/usr/include
End of search list.
"/usr/bin/ld" -m i386pep -Bdynamic -o hello.exe /usr/x86_64-w64-mingw32/lib/crt2.o /usr/x86_64-w64-mingw32/lib/crtbegin.o -L/usr/x86_64-w64-mingw32/lib -L/usr/x86_64-w64-mingw32/mingw/lib -L/usr/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib /tmp/hello-c3cd48.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 /usr/x86_64-w64-mingw32/lib/crtend.o
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: cannot find -lgcc_eh: No such file or directory
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: cannot find -lgcc_eh: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Looking on the filesystem, I actually have these files installed (by the gcc-mingw-w64-x86-64-win32
package):
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/libgcc_eh.a
/usr/lib/gcc/x86_64-w64-mingw32/12-win32/libgcc.a
Indeed, if I run:
clang-15 -target x86_64-w64-mingw -o hello.exe -L/usr/lib/gcc/x86_64-w64-mingw32/12-win32 ./hello.c
It successfully compiles it.
But I don't want to change the build scripts to add -L
, so instead I do:
ln -s /usr/lib/gcc/x86_64-w64-mingw32/12-win32/libgcc*.a /usr/x86_64-w64-mingw32/lib
And that actually works.
Still, I can't help but wonder if I'm solving this problem in the right way or not. Am I using the right version of libgcc
for compiling with clang
? Am I missing some package?