Re: [Haskell-cafe] FFI for a beginner
I don't know how to make ghc load them without using either hsc2hs or c2hs. I've had better experiences with hsc, but your mileage may vary. On Apr 8, 2011 3:34 AM, "Andrew Pennebaker" <andrew.pennebaker@gmail.com> wrote: ncurses is proving too difficult to setup, so I'm working on a new library called charm. The C code works by itself, but I can't compile a Haskell wrapper for it. While the tutorials at HaskellWiki<http://www.haskell.org/haskellwiki/FFI_complete_examples>are helpful, they're outdated. Argh! The docs<http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#glasgow-foreign-headers>say that -#include pragmas no longer work, but fail to explain how to load code without them. Suffice to say I have no recourse but trial and error. GitHub: charm <https://github.com/mcandre/charm> and hscharm<https://github.com/mcandre/hscharm> <https://github.com/mcandre/charm>$ make cp /usr/include/charm.c . ghc --make -fforce-recomp -o hellocharm hellocharm.hs charm.hs charm.c -I/usr/include -dylib-install-name /usr/lib/libcharm.dynlib [1 of 2] Compiling Charm ( charm.hs, charm.o ) [2 of 2] Compiling Main ( hellocharm.hs, hellocharm.o ) Linking hellocharm ... ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o collect2: ld returned 1 exit status make: *** [hellocharm] Error 1 Cheers, Andrew Pennebaker www.yellosoft.us _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
hsc2hs and c2hs are good suggestions, and some of the tutorials I'm following use them. But 1) Many Haskell FFI tutorials don't require them, so they only seem to help, or only help in older versions of GHC. And 2) When I did compile using c2hs, it just produced the same file, but with filler comments like {#- LINE 13 #-}. And they still refused to compile for the same reason: ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o Cheers, Andrew Pennebaker www.yellosoft.us On Sat, Apr 9, 2011 at 9:50 PM, Jason Dagit <dagitj@gmail.com> wrote:
I don't know how to make ghc load them without using either hsc2hs or c2hs. I've had better experiences with hsc, but your mileage may vary.
On Apr 8, 2011 3:34 AM, "Andrew Pennebaker" <andrew.pennebaker@gmail.com> wrote:
ncurses is proving too difficult to setup, so I'm working on a new library called charm. The C code works by itself, but I can't compile a Haskell wrapper for it. While the tutorials at HaskellWiki<http://www.haskell.org/haskellwiki/FFI_complete_examples>are helpful, they're outdated. Argh! The docs<http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#glasgow-foreign-headers>say that -#include pragmas no longer work, but fail to explain how to load code without them. Suffice to say I have no recourse but trial and error.
GitHub: charm <https://github.com/mcandre/charm> and hscharm<https://github.com/mcandre/hscharm>
<https://github.com/mcandre/charm>$ make cp /usr/include/charm.c . ghc --make -fforce-recomp -o hellocharm hellocharm.hs charm.hs charm.c -I/usr/include -dylib-install-name /usr/lib/libcharm.dynlib [1 of 2] Compiling Charm ( charm.hs, charm.o ) [2 of 2] Compiling Main ( hellocharm.hs, hellocharm.o ) Linking hellocharm ... ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o collect2: ld returned 1 exit status make: *** [hellocharm] Error 1
Cheers,
Andrew Pennebaker www.yellosoft.us
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
FIXED IT!!! The problem with charm.hs and its FFI dependency charm.c is that both want to produce an intermediary charm.o file. Solution: rename charm.hs to hscharm.hs. Cheers, Andrew Pennebaker www.yellosoft.us On Tue, Apr 12, 2011 at 5:55 PM, Andrew Pennebaker < andrew.pennebaker@gmail.com> wrote:
hsc2hs and c2hs are good suggestions, and some of the tutorials I'm following use them.
But 1) Many Haskell FFI tutorials don't require them, so they only seem to help, or only help in older versions of GHC.
And 2) When I did compile using c2hs, it just produced the same file, but with filler comments like {#- LINE 13 #-}. And they still refused to compile for the same reason:
ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o
Cheers,
Andrew Pennebaker www.yellosoft.us
On Sat, Apr 9, 2011 at 9:50 PM, Jason Dagit <dagitj@gmail.com> wrote:
I don't know how to make ghc load them without using either hsc2hs or c2hs. I've had better experiences with hsc, but your mileage may vary.
On Apr 8, 2011 3:34 AM, "Andrew Pennebaker" <andrew.pennebaker@gmail.com> wrote:
ncurses is proving too difficult to setup, so I'm working on a new library called charm. The C code works by itself, but I can't compile a Haskell wrapper for it. While the tutorials at HaskellWiki<http://www.haskell.org/haskellwiki/FFI_complete_examples>are helpful, they're outdated. Argh! The docs<http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#glasgow-foreign-headers>say that -#include pragmas no longer work, but fail to explain how to load code without them. Suffice to say I have no recourse but trial and error.
GitHub: charm <https://github.com/mcandre/charm> and hscharm<https://github.com/mcandre/hscharm>
<https://github.com/mcandre/charm>$ make cp /usr/include/charm.c . ghc --make -fforce-recomp -o hellocharm hellocharm.hs charm.hs charm.c -I/usr/include -dylib-install-name /usr/lib/libcharm.dynlib [1 of 2] Compiling Charm ( charm.hs, charm.o ) [2 of 2] Compiling Main ( hellocharm.hs, hellocharm.o ) Linking hellocharm ... ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o collect2: ld returned 1 exit status make: *** [hellocharm] Error 1
Cheers,
Andrew Pennebaker www.yellosoft.us
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
FIXED IT!!! The problem with charm.hs and its FFI dependency charm.c is that both want to produce an intermediary charm.o file. Solution: rename charm.hs to hscharm.hs. Would you (or anyone else) care to update the tutorials on the Haskell Wiki? As someone wrote below: While the tutorials at HaskellWiki<http://www.haskell.org/haskellwiki/FFI_complete_examples> are helpful, they're outdated. Argh! It would be great if someone was public-spirited enough to fix this. The root page is here http://haskell.org/haskellwiki/GHC/Using_the_FFI which in turn links to the "complete examples" page mentioned above. The docs<http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#glasgow-foreign-headers> say that -#include pragmas no longer work, but fail to explain how to load code without them. Suffice to say I have no recourse but trial and error." Ah, now that is a GHC documentation question. Can you tell us what should the docs should say instead? Then we can fix the docs. Simon From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Andrew Pennebaker Sent: 14 July 2011 07:57 To: Jason Dagit Cc: Haskell Cafe Subject: Re: [Haskell-cafe] FFI for a beginner FIXED IT!!! The problem with charm.hs and its FFI dependency charm.c is that both want to produce an intermediary charm.o file. Solution: rename charm.hs to hscharm.hs. Cheers, Andrew Pennebaker www.yellosoft.us<http://www.yellosoft.us> On Tue, Apr 12, 2011 at 5:55 PM, Andrew Pennebaker <andrew.pennebaker@gmail.com<mailto:andrew.pennebaker@gmail.com>> wrote: hsc2hs and c2hs are good suggestions, and some of the tutorials I'm following use them. But 1) Many Haskell FFI tutorials don't require them, so they only seem to help, or only help in older versions of GHC. And 2) When I did compile using c2hs, it just produced the same file, but with filler comments like {#- LINE 13 #-}. And they still refused to compile for the same reason: ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o Cheers, Andrew Pennebaker www.yellosoft.us<http://www.yellosoft.us> On Sat, Apr 9, 2011 at 9:50 PM, Jason Dagit <dagitj@gmail.com<mailto:dagitj@gmail.com>> wrote: I don't know how to make ghc load them without using either hsc2hs or c2hs. I've had better experiences with hsc, but your mileage may vary. On Apr 8, 2011 3:34 AM, "Andrew Pennebaker" <andrew.pennebaker@gmail.com<mailto:andrew.pennebaker@gmail.com>> wrote: ncurses is proving too difficult to setup, so I'm working on a new library called charm. The C code works by itself, but I can't compile a Haskell wrapper for it. While the tutorials at HaskellWiki<http://www.haskell.org/haskellwiki/FFI_complete_examples> are helpful, they're outdated. Argh! The docs<http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#glasgow-foreign-headers> say that -#include pragmas no longer work, but fail to explain how to load code without them. Suffice to say I have no recourse but trial and error. GitHub: charm<https://github.com/mcandre/charm> and hscharm<https://github.com/mcandre/hscharm> $ make cp /usr/include/charm.c . ghc --make -fforce-recomp -o hellocharm hellocharm.hs charm.hs charm.c -I/usr/include -dylib-install-name /usr/lib/libcharm.dynlib [1 of 2] Compiling Charm ( charm.hs, charm.o ) [2 of 2] Compiling Main ( hellocharm.hs, hellocharm.o ) Linking hellocharm ... ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o collect2: ld returned 1 exit status make: *** [hellocharm] Error 1 Cheers, Andrew Pennebaker www.yellosoft.us<http://www.yellosoft.us> _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org<mailto:Haskell-Cafe@haskell.org> http://www.haskell.org/mailman/listinfo/haskell-cafe
I think you should definitely use hsc2hs. It is simple to you use and would allow you to replace things like: peek ptr = do* a <- peekByteOff ptr 0 b <- peekByteOff ptr 4* return (MyStructType a b) By: #include "MyStruct.h" -- ^ Needs to be defined in a separate header peek ptr = do a <- (#peek MyStruct, foo) ptr b <- (#peek MyStruct, bar) ptr return (MyStructType a b) But I just know hsc2hs. Does c2hs automatically writes the Storable instances ? (Because it's kind of a daunting task...) 2011/4/12 Andrew Pennebaker <andrew.pennebaker@gmail.com>
hsc2hs and c2hs are good suggestions, and some of the tutorials I'm following use them.
But 1) Many Haskell FFI tutorials don't require them, so they only seem to help, or only help in older versions of GHC.
And 2) When I did compile using c2hs, it just produced the same file, but with filler comments like {#- LINE 13 #-}. And they still refused to compile for the same reason:
ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o
Cheers,
Andrew Pennebaker www.yellosoft.us
On Sat, Apr 9, 2011 at 9:50 PM, Jason Dagit <dagitj@gmail.com> wrote:
I don't know how to make ghc load them without using either hsc2hs or c2hs. I've had better experiences with hsc, but your mileage may vary.
On Apr 8, 2011 3:34 AM, "Andrew Pennebaker" <andrew.pennebaker@gmail.com> wrote:
ncurses is proving too difficult to setup, so I'm working on a new library called charm. The C code works by itself, but I can't compile a Haskell wrapper for it. While the tutorials at HaskellWiki<http://www.haskell.org/haskellwiki/FFI_complete_examples>are helpful, they're outdated. Argh! The docs<http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#glasgow-foreign-headers>say that -#include pragmas no longer work, but fail to explain how to load code without them. Suffice to say I have no recourse but trial and error.
GitHub: charm <https://github.com/mcandre/charm> and hscharm<https://github.com/mcandre/hscharm>
<https://github.com/mcandre/charm>$ make cp /usr/include/charm.c . ghc --make -fforce-recomp -o hellocharm hellocharm.hs charm.hs charm.c -I/usr/include -dylib-install-name /usr/lib/libcharm.dynlib [1 of 2] Compiling Charm ( charm.hs, charm.o ) [2 of 2] Compiling Main ( hellocharm.hs, hellocharm.o ) Linking hellocharm ... ld: duplicate symbol _Charm_getWidth_info in charm.o and charm.o collect2: ld returned 1 exit status make: *** [hellocharm] Error 1
Cheers,
Andrew Pennebaker www.yellosoft.us
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (4)
-
Andrew Pennebaker -
Jason Dagit -
Simon Peyton-Jones -
Yves Parès