I'm on Arch Linux, and I have a C SDL2 program, contained in single main.cpp
file, and I compile it for Linux with such command:
g main.cpp -lSDL2 -lSDL2_image
Now I wanna compile it for windows. Any advice on what should I do?
CodePudding user response:
I suggest my own tool, quasi-msys2, which lets you reuse the precompiled SDL2 for MinGW provided by MSYS2 (and more).
Install Clang, LLD, make
, wget
, tar
, zstd
, gpg
.
git clone https://github.com/HolyBlackCat/quasi-msys2
cd quasi-msys2/
make install _gcc _SDL2 _SDL2_image
env/shell.sh
win-clang main.cpp `pkg-config --cflags --libs sdl2 SDL2_image`
This should produce a.exe
, which you can test using wine a.exe
(or just ./a.exe
, after running env/shell.sh
).
How to do this manually:
For completeness, SDL2 itself distributes precompiled binaries for MinGW, meaning the manual setup is not hard. Any tutorial for MinGW should work.
Install MinGW from your package manager.
Download and unpack SDL2-devel-??-mingw.zip
and SDL2_image-devel-??-mingw.zip
.
Specify the paths to the directories with .a
files using -L...
and to .h
files using -I...
. Add -lmingw32 -lmingw32 -mwindows -lSDL2main -lSDL2 -lSDL2_image
to the linker flags.
Follow this troubleshooting guide if you get stuck.
CodePudding user response:
Consider using Cygwin. When I need to compile C code on windows I follow this instructions and they work fine for me. You may select other specific packages you need from the installation list.