【问题标题】:Installing SDL on Windows for Haskell (GHC)在 Windows 上为 Haskell (GHC) 安装 SDL
【发布时间】:2014-09-03 01:55:03
【问题描述】:

背景:

我一直在使用光泽库进行一些简单的图表工作。但是当需要更多交互性的时候,我发现我想要一个更强大的库。在做了一些研究之后,我决定我喜欢 SDL 库的特性,并想尝试为它安装 Haskell 绑定。我到这一步都没有成功。

第 1 部分:

如何安装和配置 SDL 二进制文件以便 Haskell 绑定可以使用它们?

第 2 部分:

Hackage 上众多且记录不充分的 SDL 包中,哪一个是社区中当前首选的绑定?如何让该软件包正确安装?

第 3 部分:(可选)

如果 SDL 不适合 Haskell 开发,那么首选的替代方案是什么?

【问题讨论】:

  • 你运行的是什么操作系统?
  • @Mokosha Title 提到了 Windows。
  • 我想谈谈第 3 部分:SDL 和 Haskell 完美结合,但如果您真的想利用 Haskell 的强大功能,无论是作为一种函数式语言,还是它作为一种美丽而令人惊叹的语言,在 GUI 应用程序中:使用 FRP (Functional Reactive Programming)。在实践方面,我推荐反应性香蕉或钠 - 它们几乎相同(这很有趣,因为它从来都不是故意的,只是碰巧如此)。
  • 我正在运行 Windows 7。
  • 你想试验还是真正生产一些东西?我问的原因是,在 Windows 上运行它是一个很大的痛苦,安装 Linux VM 并在那里试验 Haskell/SDL 更容易

标签: haskell sdl cabal


【解决方案1】:

我将回答你关于 SDL2 的问题(经过一些修改也应该适用于 SDL1)。

  1. 为 Windows 安装 pkg-config (How to install pkg config in windows?)

    这个工具非常重要。它被各种 Cabal 包用来搜索库并包含链接和编译的说明。

  2. 下载适用于 Windows/MinGW 的 SDL 开发库: http://libsdl.org/release/SDL2-devel-2.0.3-mingw.tar.gz

    如果你已经安装了32位版本的Haskell平台,解压文件夹i686-w64-mingw32

    对于 64 位版本,提取 x86_64-w64-mingw32

    你会得到以下布局:

    包括
    分享
    垃圾箱

  3. 使用 pkg-config“注册”库。

    要么将 lib/pkgconfig/sdl2.pc 复制到您的 pkg-config.exe 文件夹中,要么相应地修改/创建 PKG_CONFIG_PATH。检查您是否正确设置了所有内容:

    C:\pkg-config --list-all | grep sdl2

    sdl2 sdl2 - Simple DirectMedia Layer 是一个跨平台的多媒体 库旨在提供对音频、键盘、 鼠标、操纵杆、通过 OpenGL 的 3D 硬件和 2D 视频帧缓冲区。

  4. 将 bin 文件夹添加到 PATH 环境变量中。

  5. 通过 Cabal 安装程序安装 sdl2 包,并告诉 Cabal 在哪里可以找到您的库。

    示例: cabal install sdl2 --extra-include-dirs=C:\lib\sdl2\include --extra-lib-dirs=C:\lib\sdl2\lib\

为了测试我的安装,我写了一个小例子:

https://github.com/ftl2014/haskell-stuff/blob/master/sdl/

告诫购买者:

如果 Cabal 抱怨“缺少”库,则可能是实际找到了库但它不兼容(例如,使用 32 位版本而不是 64 位版本)或损坏。头文件也是如此。 出于某种原因,Cabal 抱怨找不到 SDL.h,我不得不使用存档根目录中的头文件(但也许我只是喝了太多 Kool-aid)。

【讨论】:

    【解决方案2】:

    我无法将它安装到我的系统上。这是我尝试过的。奇怪的是,我能够配置找到头文件而不是实际的二进制文件。

    让我们试试吧。我已经安装了新的 2014 Haskell 平台。

    cabal install sdl
    
    Configuring SDL-0.6.5...
    setup.exe: The package has a './configure' script. This requires a Unix
    compatibility toolchain such as MinGW+MSYS or Cygwin.
    Failed to install SDL-0.6.5
    

    Haskell Platform 中的 GHC 自带 MinGW,所以我们可能需要安装 MSYS。 MSYS page 表示要安装 minggw get,表示要安装

    名为mingw-get-setup.exe 的自动化GUI 安装程序助手是首次安装的首选方法。这将指导您正确设置 mingw-get 安装程序;然后,您将使用它来执行进一步的包安装,并管理您的安装。

    使用默认选项运行安装程序会显示以下屏幕:

    我们已经有了安装 Haskell 平台的 mingw,所以我们只点击列表中的最后一项,msys-base,然后选择“Mark for Installation”。然后,在左上角的“安装”菜单中,选择“应用更改”。这询问是否可以继续,我们选择“应用”

    这个安装程序没有把msys-base放到路径里,我们可以把它加到路径里,再试试安装sdl

    set PATH=C:\MinGW\msys\1.0\bin\;%PATH%
    cabal install sdl
    
    Configuring SDL-0.6.5...
    configure: WARNING: unrecognized options: --with-compiler, --with-gcc
    checking for sdl-config... no
    checking for sdl11-config... no
    configure: error: *** SDL not found! Get SDL from www.libsdl.org.
    If you already installed it, check it's in the path. If problem remains,
    please send a mail to the address that appears in ./configure --version
    indicating your platform, the version of configure script and the problem.
    Failed to install SDL-0.6.5
    

    我们需要下载并安装 libsdl。我去了libsdl download page,下载了Win32开发库SDL-devel-1.2.15-mingw32.tar.gz。我提取了这个存档(7-zip 可以提取 tar 存档和 gzip 压缩文件)。为方便起见,我将SDL-1.2.15 目录移动到c:。我们将按照上一个错误的建议将其添加到路径中,然后重试

    set PATH=C:\SDL-1.2.15\bin\;%PATH%
    cabal install sdl
    
    * Missing (or bad) header file: SDL/SDL.h
    * Missing C library: SDL
    This problem can usually be solved by installing the system package that
    provides this library (you may need the "-dev" version). If the library is
    already installed but in a non-standard location then you can use the flags
    --extra-include-dirs= and --extra-lib-dirs= to specify where it is.
    If the header file does exist, it may contain errors that are caught by the C
    compiler at the preprocessing stage. In this case you can re-run configure
    with the verbosity flag -v3 to see the error messages.
    

    我们可以通过添加建议的--extra-include-dirs 标志来消除此错误的一部分,但仍然会出现以下错误

    cabal install sdl --extra-include-dirs=c:\SDL-1.2.15\include
    
    * Missing C library: SDL
    This problem can usually be solved by installing the system package that
    provides this library (you may need the "-dev" version). If the library is
    already installed but in a non-standard location then you can use the flags
    --extra-include-dirs= and --extra-lib-dirs= to specify where it is.
    

    使用c:\SDL-1.2.15\binC:\SDL-1.2.15\libc:\SDL-1.2.15 添加--extra-lib-dirs 标志未能解决此问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-10
    • 2021-11-20
    • 2011-02-04
    • 2016-01-18
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    相关资源
    最近更新 更多