Hi, thank you!! I have modified the program based on a previous suggestion. rt_init is called before using any D functionality and rt_term is called after using D functionality. I did this by: 1) Placing int rt_init(); and int rt_term(); into the header file that Haskell reads
  2) Creating Haskell stubs
   foreign import ccall unsafe "FunctionsInD.h rt_init"
       d_init :: IO CInt
   foreign import ccall unsafe "FunctionsInD.h rt_term"
       d_term :: IO CInt
And then in the Main haskell program, in main, the function starts with
    d_init
and ends with
    d_term
I'm pretty sure this is working nicely, because I can allocate structs with the "new" keyword in D, and this led to segfaults before using rt_init and rt_term.

I think the problem I was having was trying to do this in a stupid way i.e. put wrappers around init and term on the D side.

However, I still do not know how to compile without the using a fake main. Compiling with -c -lib does still give me a _Dmain undefined reference. I did
    dmd -c -lib FunctionsInD.d
    ghc --make Main.hs FunctionsInD.a -lphobos2
And get
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libphobos2.so: undefined reference to `_Dmain'

On Wednesday, 6 August 2014 at 11:03:33 UTC, David Soria Parra via Digitalmars-d-learn wrote:
Jon via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> writes:

So that does indeed solve some of the problems. However, using this method, when linking I get two errors, undefined reference rt_init()
and rt_term() I had just put these methods in the header file.
 If I
put wrappers around these functions and export I get the rt_init,
rt_term is private.


rt_init is part of druntime. You need to link druntime into your program
in order to make it work.

Reply via email to