2

我想用 Qt 编译一个 SDL 项目。我下载了 SDL 框架 1.2.15,这是我的 Qt 项目文件:

TEMPLATE = app
SOURCES += main.cpp
OBJECTIVE_HEADERS += SDLMain.h
OBJECTIVE_SOURCES += SDLMain.m
LIBS += -framework Cocoa
LIBS += -F/Library/Frameworks
LIBS += -framework SDL

当我使用 Qt 5.0.2 编译时,一切都很好,但是当我使用 Qt 5.1.0 时,编译 SDLMain.m 时出现以下错误:

error: 'SDL/SDL.h' file not found

为什么 Qt 5.1 不像 Qt 5.0.2 那样处理框架?

4

1 回答 1

2

我不知道为什么它以前有效,但让我们注意以下几点:

  1. 将框架添加到LIBS仅负责链接,而不是编译。

  2. 您不需要INCLUDEPATH,这不是必需的。

  3. 您需要为链接器和编译器添加框架路径:

    // The directory where some frameworks are installed. There must
    // exist SDL.framework as a subdirectory of that directory.
    // It's simply to avoid typing the path twice.
    // It's a user variable, not interpreted by qmake
    SDL = -F/Library/Frameworks
    // Let the C/C++ compiler know where to find the frameworks.
    // This is so that when you include <xyz/foo>, it'll be replaced
    // by $$SDL/xyz.framework/Headers/foo
    // $$var is replaced by qmake by the contents of var
    QMAKE_CFLAGS += $$SDL
    QMAKE_CXXFLAGS += $$SDL
    // Since we compile some Objective C code, we need to set
    // the flags there too.
    QMAKE_OBJECTIVE_CFLAGS += $$SDL
    QMAKE_OBJECTIVE_CXXFLAGS += $$SDL
    // Let the linker know where to find the frameworks
    LIBS += $$SDL
    // Tell the linker that we want to use the SDL framework.
    LIBS += -framework SDL
    

这在 OS X 10.6 和 10.8 上都经过测试。确保你安装了 xcode,并且它是给定 OS X 可用的最新版本。你应该有

#include <SDL/SDL.h>

在你的来源。

于 2013-09-13T06:38:45.703 回答