[Haskell-cafe] Win32 Open GL / Glut Applications

Ronald Guida ronguida at mindspring.com
Fri Sep 21 14:19:10 EDT 2007

John Wicket wrote:
 > yea, that is probably what I need.  Can you post in a step-by-step way.

Here is a set of instructions for what I had to do to get FreeGLUT
working with GHCi.

Just a little warning: my instructions could be wrong in some places.
Normally, in order to verify my instructions, I would uninstall
everything, start from scratch, follow my instructions step by step,
and verify that they work.

 * I have low confidence in the accuracy of the following instructions.
 * I have only one machine.
 * I went through lots of frustration to get freeglut to work with GHCi.
 * I am not willing to risk breaking my current installation.
 * I do not know of any easy way to preserve my current installation
   and still start over from scratch to test my instuctions.

If my instructions are wrong, then please let me know, and I might
attempt to fix it.  Although I just don't understand why freeglut, the
Haskell GLUT library, and GHCi won't work together in the first place.

Here's what I would have to do if I were starting from scratch:


  This is an open source file archiver for Windows that can handle
  *.gz and *.bz2 files.  Download the Windows version and install it.

GHC 6.6.1

  This is the version of GHC that I'm using.  Download and install it.

  Download all three files, then install them in the order I have
  listed them.  Note: MinGW and MSYS need to "live" in different


    Automated MinGW installer   MinGW-5.1.3.exe
      ** When you run the installer, it will download several more
         files for you.

    MSYS: Minimal System        MSYS-1.0.10.exe


    MSYS Supplementary Tools    msysDTK-1.0.1.exe
      ** Scroll down to find "Current Release: msysDTK-1.0.1" and
         expand this tab.  Select "msysDTK-1.0.1.exe"


  The links for "zlib source code" are about halfway down the page.

  After downloading, the process (IIRC) is
    1. Unzip the source code.
    2. Start MSYS and cd to the source-code directory.
    3. Execute "./configure"
    4. Execute "make"
    5. Execute "make install"
  I don't remember having any problems with zlib.


  Note: It appears that cURL just had a minor revision on Sept 13.  I
  guess you can just try the latest version and see of things work.

  IIRC, the process is exactly the same as the zlib install process,
  and I didn't have any problems here either.


  Dependencies that you'll need: cURL and zlib  :-)
  Your darcs installation will have some holes, for example it won't
  support SSL because we didn't satisfy the SSL dependency.

  IIRC, the process here is
    1. Unzip the source code.
    2. Start MSYS and cd to the source-code directory.
    3. Execute "autoconf"
    4. Execute "./configure"
    5. Execute "make"
    6. Execute "make install"


  Here's where the hackery starts.

  1. Download the Freeglut source code and unzip it.
  2. Start MSYS and cd to the source-code directory.
  3. Execute "./configure"

  4. Download this custom makefile and put in in the "./src" directory.

  5. Download this custom def file and put in in the "./src" directory.

  6. Cd to the "./src" directory and then execute "make".
  7. Copy the "freeglut.dll" to GHC's bin directory (ghc-6.6.1/bin).
  8. Copy the *.h files from "freeglut-2.4.0/include/GL"
       to "ghc-6.6.1/include/mingw/GL".
       Note that "glut.h" will be overwritten.

  You need to use darcs to download GLUT-2.1.1.

  1. Start MSYS, create a directory for the GLUT source code,
       and cd to it.
  2. Execute "darcs get http://darcs.haskell.org/libraries/GLUT/"
       and wait a while.
  3. Cd to your new source directory.
  4. Execute "autoreconf" and wait a while.
  5. Modify "GLUT.cabal" as follows:

       Locate the line start starts with "build-depends:" and remove
       the dependencies "array" and "containers"

  5. Execute "runghc Setup.hs configure" and wait.
  6. Modify "GLUT-2.1.1/Graphics/UI/GLUT/Extensions.hs" as follows:

       Look at the last two lines:

foreign import ccall unsafe "hs_GLUT_getProcAddress" hs_GLUT_getProcAddress
   :: CString -> IO (FunPtr a)

       Change "hs_GLUT_getProcAddress" to "glutGetProcAddress"

  7. Modify "GLUT-2.1.1/cbits/HsGLUT.c" as follows:

       Look for "void* hs_GLUT_getProcAddress(char *procName)" and
       remove the whole function.

  8. Execute "runghc Setup.hs build" and wait.

  9. Execute "ghc-pkc unregister GLUT".  This unregisters the existing
     GLUT haskell library.  Also, search through GHC's directories,
     locate any glut library files (*.a, *.o, *.hi) that are in there
     and remove them.  You are deleting the existing GLUT that came
     with GHC 6.6.1 in order to replace it with Freeglut.

  10. Execute "runghc Setup.hs install".

  11. In GHC's directory, there is a file named "package.conf".  This
      file contains one extremely long line.  You need to find an
      editor that will let you insert some text into this line without
      introducing any line breaks.  Emacs can do this.

      You need to locate the text << pkgName = "GLUT" >> and then you
      need to locate << hsLibraries = ["HSGLUT-2.1.1"] >> to the right
      of there.  The very next thing to the right of "hsLibraries"
      should be << extraLibraries = [] >>.  You need to change it to
      << extraLibraries = ["freeglut"] >>.

  12. At this point, you should be able to start GHCi, load an example
      that depends on freeglut, and run it from GHCi, without getting
      any crashes or weird errors.

  13. If you want to /compile/ with GHCi, then you'll need to copy the
      freeglut.dll file into the same directory as your newly-compiled
      program.exe file.  I haven't tried static linking yet; that
      would require recompiling freeglut as a static library instead
      of a DLL.

Good Luck!

-- Ron

More information about the Haskell-Cafe mailing list