[Haskell-beginners] Anyone have problems with cabal and SDL?

Alvaro Vilanova alvivi at gmail.com
Tue Feb 22 22:05:13 CET 2011


The log says that configuration SDL tool `sdl-config` is not installed,
probably, due to you have installed SDL framework. Cabal, or the SDL package
(I dont know who has the problem here) doesn't take into account that the
system is a MacOs so it doesn't search the library as a framework.

To solve this, you have to compile the library manually, just `./configure
&&
make && sudo make install` or install it with MacPorts. Then you will be
able
to compile SDL projects. Nothing more. If you want to link and run your own
Haskell SDL projects on MacOs you have to dive in the next odyssey:

SDL has a tricky way to enable C `main` function to run graphic applications
on all systems. So first, we need a C function wich is going to be hooked by
SDL, and this function is going to run our Haskell application. We put this
main function in c_main.c [1].

To be compatible with all other plataforms we have keep our Main Haskell
function, so we rename this function in a FFI Module which will be compiled
only on MacOS, named HS_Main.hs [2].

Now we have to compile c_main.c with:

gcc -c c_main.c `sdl-config --cflags` -framework GHC

But, surprise, the GHC framework seems that is not well-formed, so gcc can
not get the
header and you have to search it manually. In my case:

find / -name "HsFFI.h"
...
/Library/Frameworks/GHC.framework/Versions/612/usr/lib/ghc-6.12.3/include/HSffi.h
...

gcc -c c_main.c `sdl-config --cflags`
-I/Library/Frameworks/GHC.framework/Versions/612/usr/lib/ghc-6.12.3/include/

And now we have a c_main.o. Next, we have to compile our HSMain which
imports
our Main module which contains the default main function.

ghc --make HSMain.hs -no-hs-main c_main.o -framework Cocoa

And if you have the default Haskell plataform for MacOs you are going to get
one surprise more:

Linking ./Main ...
ld: warning: in c_main.o, file was built for unsupported file format which
is not the architecture being linked (i386)
ld: warning: in /usr/local/lib/libSDLmain.a, file was built for unsupported
file format which is not the architecture being linked (i386)
ld: warning: in /usr/local/lib/libSDL.dylib, file was built for unsupported
file format which is not the architecture being linked (i386)

This means that you have a 32 bits GHC but gcc compiles to 64 bits. You have
3 options: give up, cross-compile c_main.c and sdl to 32 bits, compile and
install a custom haskell-plataform enabling 64 bits support.

Good luck, you will need it!

PD: With cabal is a little more easy, see TimePiece as example [3].

[1] https://gist.github.com/839329
[2] https://gist.github.com/839340
[3] http://hackage.haskell.org/package/TimePiece


2011/2/21 Tom Murphy <amindfv at gmail.com>

> When I use Cabal to get any program which depends on the SDL library, this
> is the error I get.
>
> "
> 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.
> cabal: Error: some packages failed to install:
> Raincat-1.1.1.2 depends on SDL-0.6.2 which failed to install.
> SDL-0.6.2 failed during the configure step. The exception was:
> exit: ExitFailure 1
> SDL-image-0.6.1 depends on SDL-0.6.2 which failed to install.
> SDL-mixer-0.6.1 depends on SDL-0.6.2 which failed to install.
> "
>
>
> I have SDL 1.2.14 (correctly) installed on my system.
> I'd really appreciate any help with this.
>
> Tom
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110222/db55054b/attachment.htm>


More information about the Beginners mailing list