Error installing Haskell SDL-image

by hitesh on 2008-10-10

I really like OSX, except when I have to jump through extra hoops to install things on it versus Linux. The latest challenge was installing the Haskell SDL-image bindings on Leopard.

Configure would bomb right away, saying it couldn't find the libs even though I had them installed via MacPorts.

bash-3.2$ runhaskell Setup.lhs configure
Configuring SDL-image-0.5.2...
checking for sdl-config... /opt/local/bin/sdl-config
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for IMG_Load in -lSDL_image... no
configure: error: *** SDL_image lib not found! Get SDL_image from
http://www.libsdl.org/projects/SDL_image/index.html

bash-3.2$ locate SDL_image
/opt/local/include/SDL/SDL_image.h
/opt/local/lib/libSDL_image-1.2.0.1.5.dylib
/opt/local/lib/libSDL_image-1.2.0.dylib
/opt/local/lib/libSDL_image.a
/opt/local/lib/libSDL_image.dylib
/opt/local/lib/libSDL_image.la

So if you try using the same trick I did with installing Haskell X11 libs ...

bash-3.2$ export LDFLAGS=-L/opt/local/lib; runhaskell Setup.lhs configure
Configuring SDL-image-0.5.2...
checking for sdl-config... /opt/local/bin/sdl-config
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for IMG_Load in -lSDL_image... yes
configure: creating ./config.status
config.status: creating config.mk
config.status: creating SDL-image.buildinfo
config.status: creating includes/HsSDLConfig.h
config.status: includes/HsSDLConfig.h is unchanged
bash-3.2$ runhaskell Setup.lhs build
Preprocessing library SDL-image-0.5.2...
Undefined symbols:
  "_ZCMain_main_closure", referenced from:
      _ZCMain_main_closure$non_lazy_ptr in libHSrts.a(Main.o)
  "___stginit_ZCMain", referenced from:
      ___stginit_ZCMain$non_lazy_ptr in libHSrts.a(Main.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
linking dist/build/Graphics/UI/SDL/Image/Version_hsc_make.o failed
command was: /opt/local/bin/ghc -optl-L/opt/local/lib -optl-lSDL_image dist/build/Graphics/UI/SDL/Image/Version_hsc_make.o -o dist/build/Graphics/UI/SDL/Image/Version_hsc_make

It gets further, but still fails. Now's the time to read the nice MACOSX file included with the distro. It tells you to write your own hsc2hs script to help it find certain dependencies on your system. For the most part the instructions are good, but for me it was still having trouble finding HsFFI.h. I had to add a cflag directive to make it work. So here is my myhsc2hs.

#!/bin/sh
# added include dir of /opt/local/lib/ghc-6.8.2/include
echo "/opt/local/bin/hsc2hs -v --cc=gcc --ld=gcc --cflag="-I/opt/local/lib/ghc-6.8.2/include" --lflag="-L/opt/local/lib -lSDLmain -framework AppKit -framework SDL" $@"
/opt/local/bin/hsc2hs -v --cc=gcc --ld=gcc --cflag="-I/opt/local/lib/ghc-6.8.2/include" --lflag="-L/opt/local/lib" --lflag="-lSDLmain" --lflag="-framework" --lflag="AppKit" --lflag="-framework" --lflag="SDL" "$@"

Tags: haskell, osx, sdl

Comments

blog comments powered by Disqus