Home > Net >  Lib SDL C Why wont my app compile with -static and libc
Lib SDL C Why wont my app compile with -static and libc

Time:06-19

I am trying to learn how to use SDL and I've been trying to get my app to run on other systems. when I try to compile using g -I src/include -L src/lib -o main main.cpp -lmingw32 -lSDL2main -lSDL2 -static-libgcc -static-libstdc -static I get a massive bunch of SDL errors saying undefined and the app doesn't finish compiling. However when running without -static it will compile but not include libc. How would I fix this issue while still being able to run on other systems without them installed?

I am also using MinGW-w64 for GCC

CodePudding user response:

You're missing some flags. Running pkg-config --libs --static sdl2 will tell you the right flags.

If you don't have pkg-config installed (you could get it from MSYS2), you can look up the flags manually in the file called sdl2.pc, which is shipped with SDL2.

For me this command prints -L/mingw64/lib -lSDL2main -lmingw32 -lSDL2main -lSDL2 -mwindows -lmingw32 -ldinput8 -lshell32 -lsetupapi -ladvapi32 -luuid -lversion -loleaut32 -lole32 -limm32 -lwinmm -lgdi32 -luser32 -lm -Wl,--no-undefined -lmingw32 -lSDL2main -lSDL2 -mwindows.

You also need -static, even though it doesn't appear in the output. You can remove -static-libgcc -static-libstdc , since they're implied by -static.

  • Related