在Mac OSX上的Qt Creator中使用SDL

时间:2012-12-26 01:56:56

标签: macos qt sdl qt-creator porting

我的朋友和我正在将我们的软件移植到Mac OSX。该应用程序主要基于SDL,我们很难在Qt5中连接和编译SDL。我们在代码中没有使用Qt的任何部分,除了使用IDE以实现跨平台的简化。

目前,我在/Library/Frameworks/

中有SDL框架

在application.pro中我有:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

macx {
   INCLUDEPATH += "/Library/Frameworks/SDL.framework/headers/"
}

main.cpp中,我显然有#include "SDL.h",如果我按住,请点击SDL.h,表明它正在链接到框架...

当我去构建/编译时,我得到了这个错误:

14:21:24: Running steps for project BDGame...
14:21:24: Configuration unchanged, skipping qmake step.
14:21:24: Starting: "/usr/bin/make" -w
make: Entering directory `/Users/Kite/Dropbox/Wizardry Games/BDGame/BDGame-build-Desktop_Qt_5_0_0_clang_64bit_SDK-Release'
g++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o BDGame main.o    
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
collect2: ld returned 1 exit status
make: *** [BDGame] Error 1
make: Leaving directory `/Users/Kite/Dropbox/Wizardry Games/BDGame/BDGame-build-Desktop_Qt_5_0_0_clang_64bit_SDK-Release'
14:21:24: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project BDGame (kit: Desktop Qt 5.0.0 clang 64bit (SDK))
When executing step 'Make'

enter image description here

我做错了什么阻止了Qt使用SDL?

1 个答案:

答案 0 :(得分:3)

main.cpp文件中,您必须声明int SDL_main(int, char**)函数而不是main()。您还需要获取与OS X的SDL包一起分发的SDLMain.hSDLMain.m文件。这两个文件需要引导您的Cocoa应用程序,该应用程序将进一步调用SDL_main函数。

我想你使用Qt项目(* .pro)文件。你应该有这样的东西:

qtsdl.pro

QT       -= core gui

TARGET = qtsdl
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

INCLUDEPATH += /Library/Frameworks/SDL.framework/Headers
LIBS += -framework Cocoa -framework SDL

SOURCES += \
    main.cpp

OBJECTIVE_SOURCES += \
    SDLMain.m

HEADERS += \
    SDLMain.h

的main.cpp

#include <SDL.h>

int SDL_main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    SDL_Surface *screen;

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        return 1;

    screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_HWSURFACE);
    if (!screen) {
        SDL_Quit();
        return 1;
    }

    SDL_Event event;
    bool running = true;

    while (running) {
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_QUIT:
                running = false;
                break;
            case SDL_KEYDOWN:
                running = false;
                break;
            default:
                break;
            }
        }
    }

    SDL_Quit();
    return 0;
}

SDLMain.h SDLMain.m 从SDL框架分发中获取它们。