0

I wrote a simple game (Pong) using C++ library SDL2 and tried to compile it for Windows (.exe) on Linux.

i have tried this to no avail:

x86_64-w64-mingw32-g++ -W -o test.exe test.cpp -lmingw32 -lSDL2 -lSDL2main -lopengl32 -lglu32 -mwindows

but switching the order of -lSDL2 -lSDL2main works:

x86_64-w64-mingw32-g++ -W -o test.exe test.cpp -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lglu32 -mwindows

What is happening here?

Fariz Awi
  • 43
  • 6
  • 3
    Possible dupe of [this](https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc) question. If SDL2main depends on SDL2 then it needs to be linked before SDL2. – Nathan Pierson Sep 30 '21 at 02:10
  • ...for the same reason the `.cpp` files need to be specified before libraries, if they depend on those libraries. – HolyBlackCat Sep 30 '21 at 06:55

0 Answers0