Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to 'SDL_main'

I've recently decided to try working with SDL with CodeBlocks 10.05. I started with the tutorial on http://www.sdltutorials.com/sdl-tutorial-basics and did my best to follow it. Unfortunately, I'm encountering:

..\..\..\..\..\..\SDL\SDL-1.2.15\lib\libSDLmain.a(SDL_win32_main.o):SDL_win32_main.c|| undefined reference to `SDL_main'|

when I try to compile it.

I've searched through many of the questions on this website and other tutorials (mainly the tutorial on LazyFoo and the CodeBlocks wiki) and can't seem to find a solution.

  • C:\SDL\SDL-1.2.15\include has been added in the Compiler tab (Search Directories)
  • C:\SDL\SDL-1.2.15\lib has been added in the Linker tab
  • The libraries libmingw32.a, libSDLmain.a, libSDL.dll.a are linked in that order
    • libmingw32.a from the MinGW\lib folder in the CodeBlocks installation directory
  • SDL.dll is in both the System32 folder and in the project folder

When attempting to follow the tutorial on the CodeBlocks wiki, I was told that SDL.h could not be found in the given directory (when making a new SDL project).

CApp.cpp

#include "CApp.h"
#include "SDL\SDL.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();
}

CApp.h

#ifndef CAPP_H_INCLUDED
#define CAPP_H_INCLUDED
#include "SDL\SDL.h"

class CApp{
    private:
        bool Running;
        SDL_Surface* Surf_Display;

    public:
        CApp();
        int OnExecute();

    public:
        bool OnInit();
        void OnEvent(SDL_Event* Event);
        void OnLoop();
        void OnRender();
        void OnCleanup();
};



#endif // CAPP_H_INCLUDED
like image 505
Prismriver Avatar asked May 29 '12 17:05

Prismriver


2 Answers

put these arguments to the main function. I had this problem too, and I fixed it few seconds ago.

int main(int argv, char** args) { }

like image 84
Ellias Mustellar Avatar answered Sep 28 '22 01:09

Ellias Mustellar


The only plausible reason for your problem I can think of is that when you created the file with main in it, you forgot to add it to build targets.

enter image description here

You should see CApp.cpp in the list where my main.cpp is. Right click on it and click Properties. Click on Build tab in the window that pops up. You should see this:

enter image description here

Click OK, hit Ctrl+F11 (Rebuild).

Good luck.

like image 21
jrok Avatar answered Sep 28 '22 01:09

jrok