Version française
Home     About     Download     Resources     Contact us    
Browse thread
Linking caml generated object in NT
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: Linking caml generated object in NT
> I am trying to link object files generated by ocamlopt with object files
> generated by the C compiler (cl for instance) and got a lot of unknown
> symbols errors. I tried adding some or all of the libraries in the lib
> directory, and still a few symbols remained unknown. Is there a list of
> libraries one has to link with to make this work.

The main difficulty is that some glue code is generated at link-time
when you lin with ocamlopt, so in general you can't just link together
the .obj files produced by the ocamlopt compiler using another linker.

Your best bet is to use the "-output_obj" option to build a
self-contained .lib file with all your compiled Caml code + the glue
code generated at link-time + the OCaml runtime library:

        ocamlopt -output_obj -o mycamlcode.lib <the .cmx and .cmxa files
                                                 for your program>

Then, you need to provide a main() function in C to start the Caml
code.  The following should do:

int main(int argc, char ** argv) {
        caml_startup(argv);
        return 0;
}

Finally, use the NuMega linker to link together mycamlcode.lib,
the C libraries used by your Caml code, and the main() function above.

See the "Embedding the Caml code in the C code" and "Main program in C"
sections of the chapter "Interfacing C with Objective Caml" of the manual
for more details.

I haven't tried -output_obj under Windows in a long time, so the above
might not be 100% accurate, but I hope it will help.

- Xavier Leroy