I am trying to set up SDL 2.0.3 in CodeBlocks for almost two days with no luck so far.
I am using latest version of Codeblocks, MinGW and SDL.
I think I have properly included and linked all the SDL files from lib and include directories into codeblocks by using Settings/Compiler/Search Directories
in Codeblocks.
I have also added following line into the Settings/Compiler/Linker Settings/Other Linker Options:
-lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer
I have added SDL2.dll to the project directory.
I believe I am using right SDL files. I have 64 system and I am using files from x86_64-w64-mingw32 directory. Which should be the right one for 64 system according to several tutorials on the web.
(
When you download SDL development libraries there are version for both 32 and 64 systems so there are two directories: x86_64-w64-mingw32 and i686-w64-mingw32 Their names are quite misleading in my opinion)
I have this simple testing code:
#include <SDL.h>
int main(int argc, char* argv[]) {
// Start SDL2
SDL_Init(SDL_INIT_EVERYTHING);
// Create a Window in the middle of the screen
SDL_Window *window = 0;
window = SDL_CreateWindow("Hello World!",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640, 480,
SDL_WINDOW_SHOWN);
// Delay so that we can see the window appear
SDL_Delay(2000);
// Cleanup and Quit
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
} <br>
And I compiler says the following:
mingw32-g++.exe -LC:\SDL\SDL2_2.0.3\lib -LC:\SDL\SDL2_image_2.0.0\lib -LC:\SDL\SDL2_mixer_2.0.0\lib -o bin\Debug\Snake.exe obj\Debug\main.o -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer
obj\Debug\main.o: In function `SDL_main':
D:/CodeBlocks/Snake/main.cpp:6: undefined reference to `SDL_Init'
D:/CodeBlocks/Snake/main.cpp:15: undefined reference to `SDL_CreateWindow'
D:/CodeBlocks/Snake/main.cpp:18: undefined reference to `SDL_Delay'
D:/CodeBlocks/Snake/main.cpp:21: undefined reference to `SDL_DestroyWindow'
D:/CodeBlocks/Snake/main.cpp:22: undefined reference to `SDL_Quit'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
I have followed this tutorial: https://www.youtube.com/watch?v=wWGtuc5uqF4
Things have sligthly changed, because when you download SDL development library and unzip it. It looks different, but I believe I did it at least partialy right, because compiler can at found <SDL.h>
I Know there are several same or familiar question, but none of them has accepted answer.
I will appreciate every help.
-m64
for 64 bit compilation. – user1810087