
I've been using hdirect for C <-> Haskell calls, and I've hit a bit of a snag. I'm using ghc 5.00.2 and hdirect 0.17. I've been able to call Haskell from C easily enough, but I've been unable to go the other way. I've tried following the directions in the hdirect manual, and tried building the examples in the hdirect distribution. Everything works up until final linking, where I receive undefined references. The C code should initialize the Haskell run-time, as it include the startup code: extern void startupHaskell (int argc, char* argv[]); startupHaskell(argc,argv); I'm compiling via ghc with the following options: ghc -package hdirect -fglasgow-exts -static -no-hs-main and the idl is compiled as such: ihc -s -fhs-to-c --gen-headers -fuse-ints-everywhere --output-h=.... Does hdirect work with ghc 5.00.2? I'm not receiving any errors in the build process, so I think my problems are more related to a lack of documentation, as opposed to a bug. Does anyone have any information (beyond what is in the hdirect documentation) on calling ghc-compiled code from C? The undefined references I'm getting are: undefined reference to `__init_Main' undefined reference to `Main_main_closure' Thanks in advance. I've looked though the mailing list archive and haven't found anything. If this has been answered before I apologize. --Mark

Hi,
the 0.17 documentation (and examples) wasn't updated to cover
the extra argument that startupHaskell() now takes, I'm afraid.
Attached is a version of tst.c from examples/server/ which shows
you how to now use startupHaskell() from C.
hth
--sigbjorn
btw, if you experience GHC5 compatibility problems with
HDirect-generated code, checking out a copy of the HDirect sources
from the CVS repository is a good idea. And if that doesn't clear
up the problems you're having either, then please let me know & I'll
try to sort it out.
----- Original Message -----
From: "Mark Conway Wirt"
To:
I've been using hdirect for C <-> Haskell calls, and I've hit a bit of a snag. I'm using ghc 5.00.2 and hdirect 0.17.
I've been able to call Haskell from C easily enough, but I've been unable to go the other way.
I've tried following the directions in the hdirect manual, and tried building the examples in the hdirect distribution. Everything works up until final linking, where I receive undefined references.
The C code should initialize the Haskell run-time, as it include the startup code:
extern void startupHaskell (int argc, char* argv[]); startupHaskell(argc,argv);
I'm compiling via ghc with the following options:
ghc -package hdirect -fglasgow-exts -static -no-hs-main
and the idl is compiled as such:
ihc -s -fhs-to-c --gen-headers -fuse-ints-everywhere --output-h=....
Does hdirect work with ghc 5.00.2? I'm not receiving any errors in the build process, so I think my problems are more related to a lack of documentation, as opposed to a bug. Does anyone have any information (beyond what is in the hdirect documentation) on calling ghc-compiled code from C?
The undefined references I'm getting are:
undefined reference to `__init_Main' undefined reference to `Main_main_closure'
Thanks in advance. I've looked though the mailing list archive and haven't found anything. If this has been answered before I apologize.
--Mark
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Tue, Aug 14, 2001 at 11:28:57AM -0700, Sigbjorn Finne wrote:
Hi,
the 0.17 documentation (and examples) wasn't updated to cover the extra argument that startupHaskell() now takes, I'm afraid. Attached is a version of tst.c from examples/server/ which shows you how to now use startupHaskell() from C.
Thanks for sending this. I'm still getting the undefined errors, though: [mark@elvis server]$ ghc -package hdirect -fglasgow-exts -static -no-hs-main -i../../lib -L../../lib -lhdirect -o tst tst.o libHStst.a /usr/local/ghc-5.00.2/lib/ghc-5.00.2/libHSstd.a(PrelMain__1.o): In function `__init_PrelMain': PrelMain__1.o(.text+0x20): undefined reference to `__init_Main' /usr/local/ghc-5.00.2/lib/ghc-5.00.2/libHSstd.a(PrelMain__2.o): In function `PrelMain_c_srt': PrelMain__2.o(.text+0x4): undefined reference to `Main_main_closure' /usr/local/ghc-5.00.2/lib/ghc-5.00.2/libHSstd.a(PrelMain__2.o): In function `PrelMain_c_fast1': PrelMain__2.o(.text+0x56): undefined reference to `Main_main_closure' I'll play around a bit with it to see if I can make them go away.
btw, if you experience GHC5 compatibility problems with HDirect-generated code, checking out a copy of the HDirect sources from the CVS repository is a good idea. And if that doesn't clear up the problems you're having either, then please let me know & I'll try to sort it out.
I'll try that, but I'm having problems getting the code to compile, without compiling everything. I've grabbed both fpconfig and hdirect, and there is no configure script to set up the fptools directory. At this point I can't really recompile the whole chain, as it takes about two days on my computer, and I don't have sufficient disk space. I'll see if I can get the configure script somewhere and try to compile hdirect directly. Thanks again. --Mark

I've grabbed both fpconfig and hdirect, and there is no configure script to set up the fptools directory.
You need to run autoconf. -- http://sc3d.org/rrt/ | impatience, n. the urge to do nothing

"Mark Conway Wirt" writes:
On Tue, Aug 14, 2001 at 11:28:57AM -0700, Sigbjorn Finne wrote:
Hi,
the 0.17 documentation (and examples) wasn't updated to cover the extra argument that startupHaskell() now takes, I'm afraid. Attached is a version of tst.c from examples/server/ which shows you how to now use startupHaskell() from C.
Thanks for sending this. I'm still getting the undefined errors, though:
[mark@elvis server]$ ghc -package hdirect -fglasgow-exts -static -no-hs-main -i../../lib -L../../lib -lhdirect -o tst tst.o libHStst.a /usr/local/ghc-5.00.2/lib/ghc-5.00.2/libHSstd.a(PrelMain__1.o): In function `__init_PrelMain': ....
It could be that ghc-5.00.2 doesn't include the -no-hs-main fix I committed sometime ago. If you add -v to the final link line and see an occurrence of PrelMain_mainIO_closure in the invocation of the linker, then that's the case & you're out of luck, I'm afraid. (==> you need to get hold of a CVS repo build and/or wait for 5.02).
I'll play around a bit with it to see if I can make them go away.
btw, if you experience GHC5 compatibility problems with HDirect-generated code, checking out a copy of the HDirect sources from the CVS repository is a good idea. And if that doesn't clear up the problems you're having either, then please let me know & I'll try to sort it out.
I'll try that, but I'm having problems getting the code to compile, without compiling everything. I've grabbed both fpconfig and hdirect, and there is no configure script to set up the fptools directory. At this point I can't really recompile the whole chain, as it takes about two days on my computer, and I don't have sufficient disk space. I'll see if I can get the configure script somewhere and try to compile hdirect directly.
It's high time that I bring out a new release, I think. You don't need to compile all of fptools though, the following steps should get you close: foo$ autoconf foo$ ./configure <and possibly some options> foo$ cd glafp-utils && make foo$ cd hdirect foo$ make boot foo$ cd src; make all foo$ cd lib; make all --sigbjorn

On Wed, Aug 15, 2001 at 12:22:32AM -0700, Sigbjorn Finne wrote:
It could be that ghc-5.00.2 doesn't include the -no-hs-main fix I committed sometime ago. If you add -v to the final link line and see an occurrence of PrelMain_mainIO_closure in the invocation of the linker, then that's the case & you're out of luck, I'm afraid. (==> you need to get hold of a CVS repo build and/or wait for 5.02).
That seems to be the case :-( I'll need to rebuild, as binaries for my platform are not generally released. Does anyone know when 5.02 is planned for release? I need to decide if I should wait or not. Building is very time and disk intensive --Mark

On Tue, Aug 14, 2001 at 11:28:57AM -0700, Sigbjorn Finne wrote:
Hi,
the 0.17 documentation (and examples) wasn't updated to cover the extra argument that startupHaskell() now takes, I'm afraid. Attached is a version of tst.c from examples/server/ which shows you how to now use startupHaskell() from C.
Now that 5.02 is out, I was able to get this to work with hdirect 0.18. However, there was a slight glitch. The sample code contained the following: extern void* __init_MathLibProxy; and startupHaskell(argc,argv,&__init_MathLibProxy); When I tried to link the code, __init_MathLibProxy came up undefined. In looking though the library produced, __init_MathLibProxy was in fact missing. However, there was a __stginit_MathLibProxy, and when I changed the code to startup using that symbol, the code worked as it should. Don't know if I was doing anything wrong, but I though I'd mention it in case anyone else was having problems. --Mark

Hello. Is list-like monad comprehension not supported? Is there a simple & elegant way of expressing ghc-extended pattern matching using `do' notation instead of list comprehension? (I dont want to end up using the case statement). I still dont understand monads too well so i apologize if this is a silly question. Thanks, -Amit. ------------------------------------------------------------------- Amit Garg | Office: ACES 6SEo4E Graduate Student | Phone : (512) 232-7875 Computer Sciences | Res : 2000 Pearl St. #207 University of Texas at Austin | Phone : (512) 560-6970 Homepage: http://www.cs.utexas.edu/~amitji -------------------------------------------------------------------

Er, i found the relevant discussion thread http://www.mail-archive.com/haskell@haskell.org/msg03115.html. Also i perceive that i should be able to use the rewrite rules to achieve what i want. Thanks. -Amit. ------------------------------------------------------------------- Amit Garg | Office: ACES 6SEo4E Graduate Student | Phone : (512) 232-7875 Computer Sciences | Res : 2000 Pearl St. #207 University of Texas at Austin | Phone : (512) 560-6970 Homepage: http://www.cs.utexas.edu/~amitji ------------------------------------------------------------------- On Thu, 11 Oct 2001, Amit Garg wrote:
Hello.
Is list-like monad comprehension not supported? Is there a simple & elegant way of expressing ghc-extended pattern matching using `do' notation instead of list comprehension? (I dont want to end up using the case statement).
I still dont understand monads too well so i apologize if this is a silly question.
Thanks, -Amit.
------------------------------------------------------------------- Amit Garg | Office: ACES 6SEo4E Graduate Student | Phone : (512) 232-7875 Computer Sciences | Res : 2000 Pearl St. #207 University of Texas at Austin | Phone : (512) 560-6970 Homepage: http://www.cs.utexas.edu/~amitji -------------------------------------------------------------------
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Thanks Mark,
I'll make sure that this fix is included. Bug reports /
suggestions on how to improve HDirect are most welcome
(many thanks to Mike Thomas for his most recent feedback);
my intention is to stabilise the hdirect-0.18 bits for a
while before releasing it properly (and move on to 0.19)
--sigbjorn
----- Original Message -----
From: "Mark Conway Wirt"
To: "Sigbjorn Finne"
On Tue, Aug 14, 2001 at 11:28:57AM -0700, Sigbjorn Finne wrote:
Hi,
the 0.17 documentation (and examples) wasn't updated to cover the extra argument that startupHaskell() now takes, I'm afraid. Attached is a version of tst.c from examples/server/ which shows you how to now use startupHaskell() from C.
Now that 5.02 is out, I was able to get this to work with hdirect 0.18. However, there was a slight glitch.
The sample code contained the following:
extern void* __init_MathLibProxy;
and
startupHaskell(argc,argv,&__init_MathLibProxy);
When I tried to link the code, __init_MathLibProxy came up undefined. In looking though the library produced, __init_MathLibProxy was in fact missing. However, there was a __stginit_MathLibProxy, and when I changed the code to startup using that symbol, the code worked as it should.
Don't know if I was doing anything wrong, but I though I'd mention it in case anyone else was having problems.
--Mark
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (5)
-
Amit Garg
-
Mark Conway Wirt
-
Mark Conway Wirt
-
Reuben Thomas
-
Sigbjorn Finne