【问题标题】:SDL framework include on MacOS QtSDL 框架包含在 MacOS Qt 上
【发布时间】:2013-09-16 07:30:25
【问题描述】:

我想用 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 那样处理框架?

【问题讨论】:

    标签: qt frameworks sdl


    【解决方案1】:

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

    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>
    

    在您的来源中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 2023-03-30
      • 1970-01-01
      • 2021-04-15
      • 2018-03-14
      • 1970-01-01
      • 2017-10-17
      • 2016-10-20
      相关资源
      最近更新 更多