Windows 7, 64x
First off, I have basic knowledge in C++. I know how to write code and use header/source files and classes. I don’t really understand linking libraries and dlls and all of that entirely and am a little lost and need some help setting SDL2 up in Code Blocks.
Building and compiling works fine in a basic project. However when I try to use SDL, I keep getting errors.
I think I might be having some problems when it comes to setting-up/linking SDL 2.0.0 in Code Blocks (w/MinGW) considering the only tutorials I can find are all for 1.2 versions. I’ve been trying to find solutions online for many hours and have found similar situations but trying to use the proposed solution never seems to work.
As far as my attempts go, I’ve been messing around with settings, files, and the code and I get different errors.
These are samples from the project:
Header File:
#ifndef CAPP_H
#define CAPP_H
#include “include/SDL/SDL.h”
class CApp
{
private:
bool Running;
SDL_Window* Surf_Display;
public:
CApp();
int OnExecute();
public:
bool OnInit();
void OnEvent(SDL_Event* Event);
void OnLoop();
void OnRender();
void OnCleanup();
};
#endif
Source File:
#include “CApp.h”
CApp::CApp()
{
Surf_Display = NULL;
Running = true;
}
int CApp::OnExecute()
{
if(OnInit() == false)
{
return -1;
}
SDL_Event Event;
while(Running)
{
while(SDL_PollEvent(&Event))
{
OnEvent(&Event);
}
OnLoop();
OnRender();
}
OnCleanup();
return 0;
}
int main(int argc, char* argv[])
{
CApp theApp;
return theApp.OnExecute();
}
Settings > Compiler… > Global compiler settings - Linker settings
Nothing in link libraries.
Other linker options: -lmingw32 -lSDLmain -lSDL
When trying to change the directory in #include “SDL.h”, it sometimes says it can’t find the directory.
So I change it to “SDL/SDL.h” and if I get Error Set #2, I change -lSDLmain and -lSDL under “Other linker options” to -lSDL2main and lSDL2.dll. Then Error Set #2 doesn’t appear but Error Set #1 does.
Error Set #1:
Various undefinded references to SDL functions.
Undefinded reference to WinMain at 16.
-------------- Build: Debug in SDLTesting (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -o bin\Debug\SDLTesting.exe obj\Debug\CApp.o obj\Debug\CApp_OnCleanup.o obj\Debug\CApp_OnEvent.o obj\Debug\CApp_OnInit.o obj\Debug\CApp_OnLoop.o obj\Debug\CApp_OnRender.o -mwindows
obj\Debug\CApp.o: In function ZN4CApp9OnExecuteEv': C:/Users/User/Documents/Coding/SDLTesting/CApp.cpp:20: undefined reference to
SDL_PollEvent’
obj\Debug\CApp_OnCleanup.o: In function ZN4CApp9OnCleanupEv': C:/Users/User/Documents/Coding/SDLTesting/CApp_OnCleanup.cpp:5: undefined reference to
SDL_Quit’
obj\Debug\CApp_OnInit.o: In function ZN4CApp6OnInitEv': C:/Users/User/Documents/Coding/SDLTesting/CApp_OnInit.cpp:5: undefined reference to
SDL_Init’
C:/Users/User/Documents/Coding/SDLTesting/CApp_OnInit.cpp:10: undefined reference to SDL_CreateWindow' 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 at 16’
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
5 errors, 0 warnings (0 minutes, 0 seconds)
Error Set #2:
ld.exe cannot find -lSDLmain
ld.exe cannot find -lSDL