<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/01/20fa3986427e9a20279dfbab9196cc6c"
  from="Dmitri Boulytchev &lt;db@t...&gt;"
  author="Dmitri Boulytchev"
  date="2009-01-25T20:10:21"
  subject="Statically linking with C object files by bootstrap ocamlc under Cygwin."
  prev="2009/01/9912c0d7556d1bea5bb7d407674e98fb"
  next="2009/01/52ac39b9d6d1ee986f640f1c9b433b18"
  prev-thread="2009/01/9912c0d7556d1bea5bb7d407674e98fb"
  next-thread="2009/01/075c78daae5e116a1bb9600fe4622e71"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Statically linking with C object files by bootstrap ocamlc under Cygwin.">
<msg 
  url="2009/01/20fa3986427e9a20279dfbab9196cc6c"
  from="Dmitri Boulytchev &lt;db@t...&gt;"
  author="Dmitri Boulytchev"
  date="2009-01-25T20:10:21"
  subject="Statically linking with C object files by bootstrap ocamlc under Cygwin.">
</msg>
</thread>

<contents>
    Hello,

    just curious: why can't I produce mixed ocaml+c executable using 
bootstrap compiler?
    File test.ml:

      external cstring: unit -&gt; string = "cstring";;
      Printf.printf "%s\n" (cstring ())

    File testc.c:

      #include &lt;ctype.h&gt;
      #include &lt;mlvalues.h&gt;
      #include &lt;alloc.h&gt; 
      #include &lt;memory.h&gt;
      #include &lt;fail.h&gt;
      #include &lt;string.h&gt;

      CAMLprim value cstring()
     {
       CAMLparam0();
       CAMLlocal1(res);
       char * q;

       res = alloc_string(7);
       q = String_val(res);

       strcpy (q, "Hello!");
       CAMLreturn(res);
    }

    $ gcc -I ../byterun -c testc.c
    $ ../boot/ocamlrun.exe ../boot/ocamlc -nostdlib -I ../boot -custom 
-o test testc.o test.ml
    ../boot/libcamlrun.a(unix.o):unix.c:(.text+0x465): undefined 
reference to `_flexdll_dlopen'
    ../boot/libcamlrun.a(unix.o):unix.c:(.text+0x478): undefined 
reference to `_flexdll_dlclose'
    ../boot/libcamlrun.a(unix.o):unix.c:(.text+0x492): undefined 
reference to `_flexdll_dlsym'
    ../boot/libcamlrun.a(unix.o):unix.c:(.text+0x4ae): undefined 
reference to `_flexdll_dlopen'
    ../boot/libcamlrun.a(unix.o):unix.c:(.text+0x4bd): undefined 
reference to `_flexdll_dlsym'
    ../boot/libcamlrun.a(unix.o):unix.c:(.text+0x4ca): undefined 
reference to `_flexdll_dlerror'
   collect2: ld returned 1 exit status
   File "test.ml", line 1, characters 0-1:
   Error: Error while building custom runtime system

   $ ../boot/ocamlrun.exe ../ocamlc -nostdlib -I ../boot -custom -o test 
testc.o test.ml
   $ ./test
   Hello!

   What do I do wrong?

   Best regards,
   Dmitri Boulytchev,
   St.Petersburg State University.
  

</contents>

</message>

