0

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
snap64
  • 53
  • 1
  • 6
  • 2
    Looks like you are missing the SDL library; post the complete linker output – trojanfoe Aug 23 '14 at 08:43
  • possible duplicate of [undefined reference to \`WinMain@16'](http://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16) – πάντα ῥεῖ Aug 23 '14 at 08:44
  • you also don't seem to be initialising SDL although this wouldn't be an issue at compile time, it would manifest at runtime. – TPS Aug 23 '14 at 18:06
  • @trojanfoe What's the complete linker output and how do I get it? I currently have mingw32, SDL2main, and SDL2 in my – snap64 Aug 23 '14 at 18:08
  • I was editing my previous comment but accidentally saved it and now it won't let me anymore, I was going to say "in my linked libraery's list" – snap64 Aug 23 '14 at 18:39
  • I don't know to get it with Code Blocks as I don't use it, but it's important to see what the linker is doing. – trojanfoe Aug 23 '14 at 18:48
  • @πάνταῥεῖ I found the solution to the WinMain error, it was a problem related to SDL defining their own `main()` and I just had to add `#undef main` to fix it. However, I still can't figure out the other error with `SDL_PollEvent`. It's very peculiar since it's defined in the same file as `SDL_Event` yet that gave no errors, I really have no idea what's wrong. – snap64 Aug 24 '14 at 09:23
  • @trojanfoe Well I can't find any linker output, but I do know the library's I entered to be linked are "mingw32", "SDL2main", and "SDL2", and I also know that the compiler is GNU GCC. I don't know much about what it's really doing as Code Blocks just asks for the library names and then generates the commands and everything itself, but I guess it uses generic commands for linking them. – snap64 Aug 24 '14 at 09:31
  • I just noticed that the `SDL_PollEvent` defined in SDL_Events.h is not implemented there, and I suppose it must just be missing the file where it's implemented, but I don't know where to find this, but the line where it's defined is `extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);` if that helps. I still have no idea how to fix this though. Thanks for the help :) – snap64 Aug 24 '14 at 09:48
  • @trojanfoe I think I just found the linker code used, I'll add it to th original post, so could you please have a look at it and try to help me? – snap64 Aug 24 '14 at 19:23

1 Answers1

0

I have now solved my problems, it took me a while to find the solutions. For the WinMain@15 error I was getting, I found out it was because SDL defines it's own main function, so I had to add #undef main to my source. For the other issue I was having, it seems I was using the wrong lib and include files which was giving me the errors, I found I had to use the 32bit mingw files.

snap64
  • 53
  • 1
  • 6