I am getting these 2 errors when trying to create my first SDL application, although I'm not sure if they're related. I've tried to find the reason for each, but nothing I found has helped me. I'm using SDL 2.0.3 and am on Windows 7.
I've looked up the WinMain
error and I found it might be trying to compile as windows application rather than console. So I made sure it was console in my project settings and it still gave me that error(though I'm not entirely sure what it's supposed to be set to for an SDL game).
Any related problems to the SDL_PollEvent
error I've found are usually linking issues which involve more than just the one line. However, I'm fairly certain I have it linked properly as I did have linking problems previously which I resolved, and I have another reference to SDL_Event
which gives no error. This seems particularly strange since both SDL_PollEvent
and SDL_Event
are in the same header file.
Here is my source and the full error output:
CApp.h:
#ifndef CAPP_H_INCLUDED
#define CAPP_H_INCLUDED
#include <SDL.h>
class CApp{
private:
bool Running;
public:
CApp();
int OnExecute();
bool OnInit();
void OnEvent(SDL_Event* event);
void OnLoop();
void OnRender();
void OnCleanup();
};
bool CApp::OnInit(){
return true;
}
void CApp::OnEvent(SDL_Event* event){
}
void CApp::OnLoop(){
}
void CApp::OnRender(){
}
void CApp::OnCleanup(){
}
CApp.cpp:
#include "CApp.h"
CApp::CApp(){
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(){
CApp theApp;
return theApp.OnExecute();
}
Error output:
||=== Build: Debug in CApp (compiler: GNU GCC Compiler) ===|
obj\Debug\CApp.o||In function `ZN4CApp9OnExecuteEv':|
C:\Users\UserName\C++ Projects\Test Platformer\CApp.cpp|17|undefined reference to `SDL_PollEvent'|
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'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Thanks in advance for any help :)
Edit:
Linker ourput:
mingw32-g++.exe -LC:\SDL\SDL2-2.0.3\lib\x64 -LC:\SDL\SDL2-2.0.3\lib -o "bin\Debug\Test Platformer.exe" obj\Debug\CApp.o -lmingw32 -lSDL2main -lSDL2 -lgdi32
obj\Debug\CApp.o: In function `ZN4CApp9OnExecuteEv':
C:/Users/Zshandi/C++ Projects/Test Platformer/CApp.cpp:17: undefined reference to `SDL_PollEvent'
collect2.exe: error: ld returned 1 exit status