I'm trying to import the SDL2 library and followed these two tutorials:
https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php
https://www.youtube.com/watch?v=QV6bOYbT_-I&t=57s
However, after I changed the project's properties accordingly (add search directory, edit linker options, add library directory etc. ), pasted the code and put the .dll file into the project folder, (it gives me no errors when debugging) it repeatedly asks me if I want to build the project, but won't execute the program or build the project. It only happens after changing the properties, the code seems to be alright.
Code (If it has something to do with it, taken from the second tutorial link):
#include <iostream>
using namespace std;
#include <SDL2/SDL.h>
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
cout << "Hello" << endl;
SDL_Window* window;
window = SDL_CreateWindow("MyWindowTitle", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_RESIZABLE);
SDL_Delay(4000);
SDL_DestroyWindow(window);
SDL_Quit();
}
I would appreciate your help!
Here:
-------------- Clean: Debug in SDL2test (compiler: GNU GCC Compiler)---------------
Cleaned "SDL2test - Debug"
-------------- Build: Debug in SDL2test (compiler: GNU GCC Compiler)---------------
gcc.exe -Wall -g -I..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\include -c C:\Users\lr\Desktop\SDL2\sdl2.c -o obj\Debug\sdl2.o
gcc.exe -L..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib -o bin\Debug\SDL2.exe obj\Debug\sdl2.o -lmingw32 -lSDL2main -lSDL2
C:\Users\lr\Desktop\SDL2\sdl2.c: In function 'SDL_main':
C:\Users\lr\Desktop\SDL2\sdl2.c:14:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib\libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.dll.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib\libSDL2.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.dll.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible ..\..\..\..\SDL2\SDL2-2.0.16\i686-w64-mingw32\lib/libSDL2.a when searching for -lSDL2
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
3 error(s), 1 warning(s) (0 minute(s), 1 second(s))
Hello again, thanks for the advice. I followed this tutorial: https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php and tried both, the 32 bit version and the 64 bit version, I also tried the compiler flags. Unfortunately, it still doesnt work.
The rebuild log looks better now, but it still shows a sort of error:
-------------- Clean: Debug in SDL2Testproject (compiler: GNU GCC Compiler)---------------
Cleaned "SDL2Testproject - Debug"
-------------- Build: Debug in SDL2Testproject (compiler: GNU GCC Compiler)---------------
Linking stage skipped (build target has no object files to link)
Nothing to be done (all items are up-to-date).
This time I used this code (from https://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php):
/*This source code copyrighted by Lazy Foo' Productions (2004-2020)
and may not be redistributed without written permission.*/
//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main( int argc, char* args[] )
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Create window
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface( window );
//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
//Update the surface
SDL_UpdateWindowSurface( window );
//Wait two seconds
SDL_Delay( 2000 );
}
}
//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
return 0;
}
Could it have something to do with the Path variable? Or with the inclusion of the header file? I've seen people mention that on other posts.