Given:

  • 32-bit Windows XP
  • 32-bit MinGW with gcc
  • 32-bit dev-versions of SDL2, SDL2_image and SDL2_ttf, unpacked in C:\MinGW\lib and C:\MinGW\include (I know that this is ugly, but I’m disdainful of Windows and me at least somehow :) ( i686-blabla directories pulled from here: SDL , SDL_image , SDL_ttf )
  • A simple program that successfully builds and works under Linux without any kicks.

Problem: does not link. By the method of googling, copy-paste and scientific spear I assembled such a team, issuing a minimum of errors:

mingw32-gcc -Wall -Dmain=SDL_main -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf src\*.c -o myprog.exe

This I have somehow solved the problems with non-found inclusions and duplicated main (my main is registered as int main(int argc, char *argv[]) according to Google's advice). However, when trying to collect all the errors it has:

 Temp\ccOZXxwh.o:amtile.c:(.text+0x6ee): undefined reference to `SDL_Init' Temp\ccOZXxwh.o:amtile.c:(.text+0x734): undefined reference to `SDL_CreateWindow' Temp\ccOZXxwh.o:amtile.c:(.text+0x759): undefined reference to `SDL_GetWindowSurface' Temp\ccOZXxwh.o:amtile.c:(.text+0x770): undefined reference to `IMG_Init' Temp\ccOZXxwh.o:amtile.c:(.text+0x810): undefined reference to `TTF_Init' Temp\ccOZXxwh.o:amtile.c:(.text+0x830): undefined reference to `TTF_OpenFont' 

Well, and so on. I tried to prescribe -LC:\MinGW\lib , check for the presence of the corresponding *.a files there - everything is there, but not going.

What am I doing wrong and how to do it right?

  • @VladimirGamalian wrote a question - andreymal
  • And mingw from here ? - Vladimir Gamalyan
  • @VladimirGamalian yes - andreymal
  • one
    I tried it myself, #include <SDL2/SDL.h>\n int main(int, char**){SDL_Init(SDL_INIT_VIDEO);} is #include <SDL2/SDL.h>\n int main(int, char**){SDL_Init(SDL_INIT_VIDEO);} normally with g++ main.cpp -lmingw32 -lSDL2main -lSDL2 -o main.exe ( win10x64, msys64) - Vladimir Gamalyan
  • @VladimirGamalian suddenly works - andreymal

2 answers 2

This is what I was in no way ready for - so much for the importance of the order of arguments.

It was (removed non-essential):

gcc -Wall -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf src\*.c -o myprog.exe

It became:

gcc -Wall src\*.c -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -o myprog.exe

That is, I just rearranged the list of files to the beginning - and everything immediately gathered, started, everything is fine.

At the same time, Linux doesn’t care about the order of arguments - it collects both this and that.


Explanation from here :

Here, in contrast to the cases considered earlier, the order of the g++ arguments is important, since -L and -l are options of the linker, which comes into operation after the compiler that processes the first argument (file name).

  • Also, the order of enumeration of libraries is important, for example, if you put -lmingw32 at the end, then there will be an undefined reference to 'WinMain@16' error undefined reference to 'WinMain@16' - Vladimir Gamalyan
  1. READY - collect the program in the window. If you are used to Linux, install mingw32-cross-gcc and build a program from Linux, but with the Windows target platform
  2. Use any Makefile generator to avoid doing tedious manual work. These can be qmake, cmake, automake or qbs. Choose.
  • one
    I agree about automating the assembly with the same cmake. But I do not agree that it is “to do it wrong” in Windows for Windows. - Vladimir Gamalyan
  • @Vladimir Gamalian Windows build requires a huge amount of fuss. At least due to the lack of a package manager - any dependency has to google. On Linux, it is enough to connect the mingw32 repository and download the missing one from it. - gbg
  • one
    I partially agree, but for example the same assembly of msys64 includes the pacman package manager, and installation for example dev booster is just pacman -S mingw-w64-i686-boost - Vladimir Gamalyan
  • one
    What is a minus? The solution is at least interesting, since having a "assembly shop" in one place is better than a bunch of separate ones for each system. Yes, it is possible that some nuances will appear, but where they do not exist. - alexis031182
  • The minus is probably due to the fact that the answer does not correspond to the question - how to get the project to go to MinGW in Windows XP. - Vladimir Gamalyan