English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] C linking on mingw
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-17 (16:31)
Subject: [Caml-list] C linking on mingw
I am having trouble linking ocamlopt code with C via a dll on mingw.
Here is a simple reproduction of the problem:


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

value c_msgbox(value i)
  s = alloc_string(15);
  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
gcc -mno-cygwin -shared /cygdrive/c/ocaml/lib/libasmrun.a msgbox.o -o

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