-1

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

  • Just link dynamically and distribute your compilers runtime libraries with your application. – Jesper Juhl Jun 17 '22 at 22:26
  • I am not sure how to do than and also it's probably better to statically link the runtime since then it can add all the runtimes required – user19227467 Jun 18 '22 at 13:03

1 Answers1

1

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.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207