简体   繁体   English

在Windows for Haskell(GHC)上安装SDL

[英]Installing SDL on Windows for Haskell (GHC)

Background: 背景:

I've been using the gloss library for some simple diagram work. 我一直在使用光泽度库进行一些简单的图表工作。 But when it came time for something more interactive, I found I wanted a more powerful library. 但是当需要进行更多交互时,我发现我想要一个功能更强大的库。 After doing some research, I decided that I liked the features of the SDL library and wanted to try to install the Haskell bindings for it. 经过研究,我决定喜欢SDL库的功能,并想尝试为其安装Haskell绑定。 I have to this point been unsuccessful. 至此,我一直没有成功。

Part 1: 第1部分:

How do I install and configure the SDL binaries so that they can be used by the Haskell bindings? 如何安装和配置SDL二进制文件,以便Haskell绑定可以使用它们?

Part 2: 第2部分:

Which one of the numerous and ill documented SDL packages on Hackage it the current preferred binding in the community? 在Hackage上众多且记录不良的SDL软件包中,哪个是当前社区中首选的绑定? How do I get that package to install correctly? 如何获得该软件包以正确安装?

Part 3: (Optional) 第3部分:(可选)

If SDL is not a good fit for haskell development what is the preferred alternative? 如果SDL不适合Haskell开发,那么首选的替代方法是什么?

I am going to answer your question for SDL2 (should also work for SDL1 with some modifications). 我将回答有关SDL2的问题(也应该对SDL1进行一些修改)。

  1. Install pkg-config for Windows ( How to install pkg config in windows? ) 为Windows安装pkg-config( 如何在Windows中安装pkg config?

    This tool is very important. 这个工具非常重要。 It is used by various Cabal packages to search for libraries and contains directions for linking and compiling. 各种Cabal软件包使用它来搜索库,并包含链接和编译的说明。

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

    If you have installed the 32-bit version of the Haskell platform, extract the folder i686-w64-mingw32 如果您已安装32位版本的Haskell平台,请解压缩文件夹i686-w64-mingw32

    For 64-bit versions extract x86_64-w64-mingw32 对于64位版本,请提取x86_64-w64-mingw32

    You will get following layout: 您将获得以下布局:

    include 包括
    share 分享
    bin 箱子
    lib LIB

  3. "Register" the library with pkg-config. 使用pkg-config“注册”该库。

    Either copy lib/pkgconfig/sdl2.pc into the folder of your pkg-config.exe or modify/create the PKG_CONFIG_PATH accordingly. 将lib / pkgconfig / sdl2.pc复制到pkg-config.exe的文件夹中,或相应地修改/创建PKG_CONFIG_PATH。 Check that you set up everything correctly: 检查所有设置是否正确:

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

    sdl2 sdl2 - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. sdl2 sdl2-简单DirectMedia层是一个跨平台的多媒体库,旨在通过OpenGL和2D视频帧缓冲提供对音频,键盘,鼠标,操纵杆,3D硬件的低级访问。

  4. Add the bin folder to your PATH environment variable. 将bin文件夹添加到PATH环境变量中。

  5. Install the sdl2 package via the Cabal installer and tell Cabal where to find your libraries. 通过Cabal安装程序安装sdl2软件包,并告诉Cabal在哪里可以找到您的库。

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

To test my installation, I have written a small example: 为了测试我的安装,我写了一个小例子:

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

Caveat emptor: 买者自负:

If Cabal complains about a "missing" library, it might be the case that library was actually found but it is incompatible (eg using a 32-bit instead of a 64-bit version) or corrupt. 如果Cabal抱怨库“丢失”,则可能是确实找到了库,但该库不兼容(例如,使用32位而不是64位版本)或已损坏。 The same is true for header files. 头文件也是如此。 For some reason, Cabal complained about not finding SDL.h, and I had to use the headers in the root include folder of the archive (but maybe I was just drinking too much Kool-aid). 由于某种原因,Cabal抱怨找不到SDL.h,因此我不得不使用存档的根头include文件夹中的标头(但也许我只是喝了太多的Kool-aid)。

I wasn't able to get it to install on my system. 我无法将其安装在系统上。 Here's what I tried. 这是我尝试过的。 Strangely, I was able to get configure find the header files but not the actual binary. 奇怪的是,我能够通过configure找到头文件,但没有找到实际的二进制文件。

Let's try it. 让我们尝试一下。 I have installed the new 2014 Haskell Platform. 我已经安装了新的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

GHC in the Haskell Platform comes with MinGW, so we probably need to install MSYS. Haskell平台中的GHC随MinGW一起提供,因此我们可能需要安装MSYS。 The MSYS page says to install minggw get , which says to install MSYS页面说要安装minggw get ,说要安装

An automated GUI installer assistant called mingw-get-setup.exe is the preferred method for first time installation. 自动化的GUI安装程序助手mingw-get-setup.exe是首次安装的首选方法。 This will guide you through the setup of the mingw-get installer proper; 这将指导您正确安装mingw-get安装程序; you will then use this to perform further package installations, and to manage your installation. 然后,您将使用它来执行进一步的软件包安装并管理安装。

Running the installer with the default options gives us the following screen: 使用默认选项运行安装程序会显示以下屏幕:

Mingw-get GUI

We already have mingw from installing the Haskell platform, so we'll click on only the last item in the list, msys-base, and select "Mark for Installation". 安装Haskell平台已经有了mingw,因此我们只单击列表中的最后一项,即msys-base,然后选择“标记为安装”。 Then, in the "Installation" menu in the top left, select "Apply Changes". 然后,在左上方的“安装”菜单中,选择“应用更改”。 This asks if it is ok to proceed, and we select "Apply" 这询问是否可以继续,然后我们选择“应用”

This installer didn't put msys-base in the path, we can add it to the path, and try installing sdl again 此安装程序未将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

We need to download and install libsdl. 我们需要下载并安装libsdl。 I went to the libsdl download page and downloaded the Win32 development libraries, SDL-devel-1.2.15-mingw32.tar.gz . 我转到libsdl下载页面,并下载了Win32开发库SDL-devel-1.2.15-mingw32.tar.gz I extracted this archive ( 7-zip can extract both tar archives and gzip compressed files). 我提取了此存档( 7-zip可以提取tar存档和gzip压缩文件)。 For convenience, I moved the SDL-1.2.15 directory to c: . 为了方便起见,我将SDL-1.2.15目录移至c: SDL-1.2.15 We'll add this to the path, as suggested by the previous error, and try again 根据上一个错误的建议,将其添加到路径中,然后重试

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.

We can make part of this error go away by adding the suggested --extra-include-dirs flag, but still get the following error 通过添加建议的--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.

Adding the --extra-lib-dirs flag with c:\\SDL-1.2.15\\bin or C:\\SDL-1.2.15\\lib or c:\\SDL-1.2.15 failed to fix this problem. 使用c:\\SDL-1.2.15\\binC:\\SDL-1.2.15\\libc:\\SDL-1.2.15添加--extra-lib-dirs标志无法解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM