caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Linking caml generated object in NT
@ 1998-10-20 13:29 Friedman Roy
  1998-10-23  9:30 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Friedman Roy @ 1998-10-20 13:29 UTC (permalink / raw)
  To: caml-list

Hi,

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 reason I am doing this is to try instrumentig my code to work with
boundschecker to discover memory leaks in my C code that is linked
together with some CAML code. To do this, I need to use NuMega linker so I
cannot use ocamlopt.)

Thanks,

Roy





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

* Re: Linking caml generated object in NT
  1998-10-20 13:29 Linking caml generated object in NT Friedman Roy
@ 1998-10-23  9:30 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 1998-10-23  9:30 UTC (permalink / raw)
  To: Friedman Roy, caml-list

> 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




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

end of thread, other threads:[~1998-10-24 14:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-20 13:29 Linking caml generated object in NT Friedman Roy
1998-10-23  9:30 ` Xavier Leroy

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).