caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] C linking on mingw
@ 2004-05-17 16:31 HENRIKSON, JEFFREY
  2004-05-17 17:33 ` Michael Hamburg
  0 siblings, 1 reply; 2+ messages in thread
From: HENRIKSON, JEFFREY @ 2004-05-17 16:31 UTC (permalink / raw)
  To: caml-list; +Cc: lists

I am having trouble linking ocamlopt code with C via a dll on mingw.
Here is a simple reproduction of the problem:

Msgbox.c:

#include <windows.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>

value c_msgbox(value i)
{
  CAMLparam0();
  CAMLlocal1(s);
  s = alloc_string(15);
  MessageBox(NULL,"yay","hello",MB_OK);
  CAMLreturn (Val_int(0));
}


(Yes, the alloc_string doesn't do anything, it's only necessary to
reproduce the situation.  Suppose I have a real function that actually
depends on the runtime.)

gcc -mno-cygwin -I /cygdrive/c/ocaml/lib -I /usr/include/w32api -c
msgbox.c
gcc -mno-cygwin -shared /cygdrive/c/ocaml/lib/libasmrun.a msgbox.o -o
msgbox.dll

msgbox.o(.text+0x11):msgbox.c: undefined reference to `_local_roots'
msgbox.o(.text+0x20):msgbox.c: undefined reference to `_local_roots'
msgbox.o(.text+0x2b):msgbox.c: undefined reference to `_local_roots'
msgbox.o(.text+0x52):msgbox.c: undefined reference to `_alloc_string'
msgbox.o(.text+0x84):msgbox.c: undefined reference to `_local_roots'
collect2: ld returned 1 exit status


What makes this link?  I am needing to do an ocamlopt program.  The only
file which resolves the linking above on my mingw distribution is
ocamlrun.dll, which of course isn't meant for asm code linking.
Specifically, it crashes before running a single line of code.  I seem
to remember there was an easy way to do this on the MS based port when I
had it set up.

PS: can someone please confirm/correct my understanding of these files:
- ocamlrun.dll: the bytecode runtime.
- ocamlrun.a: its import library.
- libasmrun.a: the runtime for asm binary programs with entry point.
- stdlib.a: utilities to support the Pervasives and standard libaries.

Are there other related files?  Must one have two separate code stub
dlls for ocaml and ocamlopt?

Thank you,


Jeff Henrikson

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] C linking on mingw
  2004-05-17 16:31 [Caml-list] C linking on mingw HENRIKSON, JEFFREY
@ 2004-05-17 17:33 ` Michael Hamburg
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Hamburg @ 2004-05-17 17:33 UTC (permalink / raw)
  To: <caml-list@inria.fr> <caml-list@inria.fr>
  Cc: <lists@lophty.com>

I actually had a similar problem, and couldn't resolve it.  I can link 
gcc into ocamlopt, and i can link either way with ocamlc, but I can't 
link ocaml code compiled with ocamlopt into a program whose main is in 
C (actually, objective-C), for exactly the same reason.

Mike Hamburg

On May 17, 2004, at 12:31 PM, HENRIKSON, JEFFREY wrote:

> I am having trouble linking ocamlopt code with C via a dll on mingw.
> Here is a simple reproduction of the problem:
>
> Msgbox.c:
>
> #include <windows.h>
> #include <caml/mlvalues.h>
> #include <caml/memory.h>
>
> value c_msgbox(value i)
> {
>   CAMLparam0();
>   CAMLlocal1(s);
>   s = alloc_string(15);
>   MessageBox(NULL,"yay","hello",MB_OK);
>   CAMLreturn (Val_int(0));
> }
>
>
> (Yes, the alloc_string doesn't do anything, it's only necessary to
> reproduce the situation.  Suppose I have a real function that actually
> depends on the runtime.)
>
> gcc -mno-cygwin -I /cygdrive/c/ocaml/lib -I /usr/include/w32api -c
> msgbox.c
> gcc -mno-cygwin -shared /cygdrive/c/ocaml/lib/libasmrun.a msgbox.o -o
> msgbox.dll
>
> msgbox.o(.text+0x11):msgbox.c: undefined reference to `_local_roots'
> msgbox.o(.text+0x20):msgbox.c: undefined reference to `_local_roots'
> msgbox.o(.text+0x2b):msgbox.c: undefined reference to `_local_roots'
> msgbox.o(.text+0x52):msgbox.c: undefined reference to `_alloc_string'
> msgbox.o(.text+0x84):msgbox.c: undefined reference to `_local_roots'
> collect2: ld returned 1 exit status
>
>
> What makes this link?  I am needing to do an ocamlopt program.  The 
> only
> file which resolves the linking above on my mingw distribution is
> ocamlrun.dll, which of course isn't meant for asm code linking.
> Specifically, it crashes before running a single line of code.  I seem
> to remember there was an easy way to do this on the MS based port when 
> I
> had it set up.
>
> PS: can someone please confirm/correct my understanding of these files:
> - ocamlrun.dll: the bytecode runtime.
> - ocamlrun.a: its import library.
> - libasmrun.a: the runtime for asm binary programs with entry point.
> - stdlib.a: utilities to support the Pervasives and standard libaries.
>
> Are there other related files?  Must one have two separate code stub
> dlls for ocaml and ocamlopt?
>
> Thank you,
>
>
> Jeff Henrikson
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: 
> http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: 
> http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-05-17 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-17 16:31 [Caml-list] C linking on mingw HENRIKSON, JEFFREY
2004-05-17 17:33 ` Michael Hamburg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).