SDL ld 返回 1 退出状态
我正在编写一个示例SDL程序,我只是编写了最简单的程序,但是由于我的SDL_pollevent()函数,我收到以下错误:
Test.cpp:(.text._ZN4CApp9OnExecuteEv[CApp::OnExecute()]+0x41): undefined reference to `SDL_PollEvent'
collect2: ld returned 1 exit status
代码是:
int OnExecute()
{
if(OnInit()==false)
return -1;
SDL_Event Event;
while(Running)
{
while(SDL_PollEvent(&Event))
{
OnEvent(&Event);
}
OnLoop();
OnRend();
}
OnClean();
return 0;
}
im writing a sample SDL program, and I just wrote the simplest program, but i get the following error because of my SDL_pollevent() function:
Test.cpp:(.text._ZN4CApp9OnExecuteEv[CApp::OnExecute()]+0x41): undefined reference to `SDL_PollEvent'
collect2: ld returned 1 exit status
and the code is:
int OnExecute()
{
if(OnInit()==false)
return -1;
SDL_Event Event;
while(Running)
{
while(SDL_PollEvent(&Event))
{
OnEvent(&Event);
}
OnLoop();
OnRend();
}
OnClean();
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,确保您包含 SDL.h,它在大多数平台上看起来像这样:
如果您使用 Xcode 在 Mac 上构建,则需要使用它:
然后确保您已链接到 SDL框架:
First, make sure you are including SDL.h, which will look like this on most platforms:
If you're building on a Mac with Xcode, you'll want to use this instead:
Then make sure you've linked against the SDL framework:
这是链接器错误。您没有正确地将 SDL 库链接到您的项目。通常您需要将
-lSDL
添加到链接器中。如果您使用的是 Windows,我相信您也必须添加-lSDLmain
。确保您的编译器知道在哪里可以找到这些文件(正确设置库路径)。如果您不知道如何执行此操作,请查看本教程<中的系统和 IDE 特定安装说明< /a>.我假设
SDL_Init()
是在OnInit()
中调用的?否则你的程序将无法正确运行。This is a linker error. You are not correctly linking the SDL libraries to your project. Usually you would need to add
-lSDL
to your linker. If you are using Windows I believe you have to add-lSDLmain
too. Make sure your compiler knows where to find these files (set your library path correctly). If you don't know how to do this, check the system and IDE specific installation instructions in this tutorial.I assume that
SDL_Init()
is called withinOnInit()
? Otherwise your program will not run correctly.