Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

c++ - 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:

............SDLSDL-1.2.15liblibSDLmain.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:SDLSDL-1.2.15include has been added in the Compiler tab (Search Directories)
  • C:SDLSDL-1.2.15lib 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 MinGWlib 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 "SDLSDL.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 "SDLSDL.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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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) { }


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...