未定义对“SDL_main”的引用 [英] Undefined reference to 'SDL_main'

查看:525
本文介绍了未定义对“SDL_main”的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近决定尝试使用CodeBlocks 10.05的SDL。我开始学习有关 http://www.sdltutorials.com/sdl-tutorial-basics并尽我所能地跟随它。很抱歉,我遇到了:

  .. \..\..\..\..\\ \\..\SDL\SDL-1.2.15\lib\libSDLmain.a(SDL_win32_main.o):SDL_win32_main.c ||未定义引用SDL_main| 



>我搜索了这个网站和其他教程(主要是关于LazyFoo和CodeBlocks wiki的教程)的许多问题,似乎找不到一个解决方案。




  • C:\SDL\SDL-1.2.15 \include已添加到编译器选项卡li>
  • C:\SDL\SDL-1.2.15 \lib已添加到链接器标签

  • 库libmingw32.a,libSDLmain。 a,libSDL.dll.a按顺序从CodeBlocks安装目录中的MinGW \lib文件夹中按顺序链接

    • libmingw32.a


  • SDL.dll位于System32文件夹和项目文件夹中



当试图按照CodeBlocks wiki上的教程时,我被告知在给定的目录中找不到SDL.h(当做一个新的SDL项目时)。



CApp.cpp

  #includeCApp.h
#includeSDL\SDL.h

CApp :: CApp(){
Surf_Display = NULL;

Running = true;
}

int CApp :: OnExecute(){
if(OnInit()== false){
return -1;
}

SDL_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
#includeSDL\SDL.h

class CApp {
private:
bool运行;
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


解决方案

我可以想到的唯一合理的原因是,当你使用 main 创建文件时,你忘了添加





您应该在我的main.cpp列表中看到CApp.cpp。右键单击它,然后单击属性。在弹出的窗口中单击Build选项卡。您应该会看到:





点击确定,按Ctrl + F11(重建)。



祝你好运。


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

解决方案

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.

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:

Click OK, hit Ctrl+F11 (Rebuild).

Good luck.

这篇关于未定义对“SDL_main”的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆