在Mac OS X Lion上使用Xcode 4设置SDL [英] Setting up SDL on Mac OS X Lion with Xcode 4

查看:200
本文介绍了在Mac OS X Lion上使用Xcode 4设置SDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使一个超级简单的SDL程序正常工作.我正在使用Mac OS X Lion.我有SDL在Snow Leopard中工作,但似乎不想在狮子中工作.到目前为止,我有这个:

I've been trying to get a super simple SDL program to work. I'm using Mac OS X Lion. I've got SDL to work in Snow Leopard, but it doesn't seem to want to work in lion. So far I have this:

#include <iostream>
#include "SDL/SDL.h"

using namespace std;

/*
#ifdef main
#  undef main
#endif
*/

int main( int argc, char* args[] )
{
    SDL_Surface* hello = NULL;
    SDL_Surface* screen = NULL;
    SDL_Init( SDL_INIT_EVERYTHING );
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
    hello = SDL_LoadBMP( "hello.bmp" );
    SDL_BlitSurface( hello, NULL, screen, NULL );
    SDL_Flip( screen );
    SDL_Delay( 2000 );
    SDL_FreeSurface( hello );
    SDL_Quit();

    return 0;
}

当我尝试编译此代码(在Xcode 4.1中)时,它给了我这个错误:

When I try to compile this code (in Xcode 4.1) it gives me this error:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
     (maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

如果我取消注释当前已注释的#ifdef内容,则程序会编译,但随后会在SDL_SetVideoMode行上收到SIGABRT.我刚刚在另一个程序中看到的那些评论过的东西,我不确定是否应该拥有它.

If I uncomment the #ifdef stuff I have commented currently, the program compiles, but then receives SIGABRT on the SDL_SetVideoMode line. That commented stuff I have I just saw in another program, I'm not sure if I'm supposed to have it or not.

我应该如何使它工作?

推荐答案

SDL头文件使用宏重新定义main.这是在SDL_main.h中:

The SDL header files redefine main with a macro. This is in SDL_main.h:

#define main    SDL_main

但这很好. SDL提供了自己的main()函数,该函数随后会调用您的版本.因此,摆脱那些定义,它们会使情况变得更糟,而不是更好.

But this is fine. SDL provides its own main() function that then calls your version. So get rid of those defines, they are making it worse, not better.

如果您的项目是基于Cocoa的,那么您可能错过了在项目中包含SDLmain.m的情况.这提供了可可友好的main()功能.如果您的项目是本机C ++,那么我的猜测是您没有在项目中包含所有SDL库,因此链接器看不到SDL自己的main().

If your project is Cocoa based, then you probably missed to include SDLmain.m in your project. This provides a Cocoa friendly main() function. If your project is native C++, then my guess is that you did not include all the SDL libs in your project, so the linker isn't seeing SDL's own main().

这篇关于在Mac OS X Lion上使用Xcode 4设置SDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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