[Haskell-cafe] c2hs and cabal?

Magnus Therning magnus at therning.org
Tue Nov 28 07:00:50 EST 2006

On Tue, Nov 28, 2006 at 11:11:30 +0000, Duncan Coutts wrote:
>On Tue, 2006-11-28 at 10:56 +0000, Magnus Therning wrote:
>> On Tue, Nov 28, 2006 at 00:33:42 +0000, Duncan Coutts wrote:
>> >On Mon, 2006-11-27 at 22:26 +0000, Magnus Therning wrote:
>> >> Can I use cabal to build packages that incorporates C libraries and FFI
>> >> Haskell created using c2hs?
>> >
>> >Yes you can. Cabal understands a bit about .chs files. I think all you
>> >need to do is specify the module in the exposed-modules or
>> >other-modules and Cabal will find the .chs file and try to build a .hs
>> >file from it.
>> I'm still having some problems though :-(  I thought I'd start with a
>> minimal, rather silly, test to see if I can get Cabal to do what I want.
>> I've stuck what I have at
>> http://www.therning.org/magnus_files/cnh.tar.gz
>> It fails to build for me with the following error:
>>  Preprocessing executables for cnh-0.1...
>>  Building cnh-0.1...
>>  [1 of 2] Compiling Foo              ( src/Foo.hs, dist/build/cnh/cnh-tmp/Foo.o )
>>  src/Foo.chs:6:8: parse error on input `import'
>> I tried using '-v5' but it didn't really offer anymore insight for a
>> novice like me :(
>Check the generated Foo.hs file to see if it looks obviously bogus.

Can't really see anything obviously bogus about the following:

  % cat Foo.chs
  module Foo where

  #include "foo.h"

  fooOne i = {# call foo1 #} i

  % cat Foo.hs
  -- GENERATED by C->Haskell Compiler, version 0.14.5 Travelling Lightly, 12 Dec 2005 (Haskell)
  -- Edit the ORIGNAL .chs file instead!

  {-# LINE 1 "src/Foo.chs" #-}module Foo where

  fooOne i = foo1 i

  foreign import ccall safe "src/Foo.h foo1"
    foo1 :: (CInt -> (IO CInt))

Or am I missing something?


Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
magnus at therning.org             Jabber: magnus.therning at gmail.com

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

"There are of course many problems connected with life, of which some
of the most popular are `Why are people born?' `Why do they die?' `Why
do they spend so much of the intervening time wearing digital

-- The Book.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20061128/945f326c/attachment.bin

More information about the Haskell-Cafe mailing list