Configure SDL2 with Eclipse and MinGW on Windows

I am trying to create an SDL2 project with Eclipse Kepler and MinGW on Windows. I already added SDL2 libs to MinGW (.a) in C: \ MinGW \ lib, SDL2 included in MinGW (C: \ MinGW \ include \ SDL2), and also added in the project properties → C / C ++ general → paths and characters -> librairies the following lines in the following order:

mingw32
SDL2main
SDL2

Then I put '-mwindows' in the MinGW C ++ linker at the end of the "Command Line Template" line

I also added -Dmain = SDL_main for the entry point ...

But the compiler gives me an error:

main.cpp: 7: undefined reference to `SDL_CreateWindow '

this is the code:

#include <SDL2/SDL.h> int main(int, char**) { SDL_Window *pWindow = nullptr; pFenetre = SDL_CreateWindow("Test SDL 2.0", 0, 0, 320, 240, SDL_WINDOW_SHOWN); if (!pWindow) { return -1; } SDL_DestroyWindow(pWindow); return 0; } 

And this is the build console:

  Info: Internal Builder is used for build
 g ++ "-LC: \\ MinGW \\ lib" -o Test.exe main.o -lmingw32 -lSDL2main -lSDL2 -mwindows 
 main.o: In function `SDL_main ':
 C: \ Users \ olivi_000 \ workspace \ Test \ Debug /../ main.cpp: 7: undefined reference to `SDL_CreateWindow '
 C: \ Users \ olivi_000 \ workspace \ Test \ Debug /../ main.cpp: 13: undefined reference to `SDL_DestroyWindow '
 C: \ MinGW \ lib / libmingw32.a (main.o): main.c :(. Text.startup + 0xa7): undefined reference to ` WinMain@16 '
 collect2.exe: erreur: ld a retourné 1 code d'état d'exécution

what's wrong?

+4
source share
1 answer

Make sure you are using the correct version of the library. You cannot mix 64-bit import libraries with a 32-bit compiler. For the loaded SDL2 library (SDL2-devel-2.0.0-mingw.tar.gz) it comes with both a 32-bit and a 64-bit version. i686-w64-mingw32 is 32-bit, and x86_64-w64-mingw32 is for 64-bit.

+4
source

Source: https://habr.com/ru/post/1490770/


All Articles