Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Building with OCamlMkLib
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-01-20 (17:22)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] Building with OCamlMkLib
John Whitington wrote:
> Hi Folks,
> I'm building a Plain C interface to our PDF libraries, but am stuck. The 
> idea is to build a library with Ocamlmklib containing the C wrapper 
> around the ocaml code.
> I've used some test files (included below) in place of the real ones.
> I can successfully build the library (I'm using OS x / intel):
> ocamlc -c -cc "cc" -ccopt " -DNATIVE_CODE -o cpdflibwrapper.o" 
> cpdflibwrapper.c
> ocamlc cpdflibc.mli
> ocamlc
> ocamlmklib -o camlpdfc cpdflibwrapper.a
> (builds, camlpdfc.a, camlpdfc.cma, camlpdfc.cmxa)
> But trying to link a C program which uses the new library fails. Do I 
> need to include something else, or have I got the ocamlmklib stage wrong?

You need to include an OCaml "main program" into your library. The 
easiest way to build a library that include the OCaml runtime, some 
OCaml code and custom C code is the -output-obj option:

ocamlc -output-obj -o cpdlibc.cmo cpdflibwrapper.o

Note that cpdflibrwrapper should define a function that calls 
caml_startup in order to start the OCaml runtime and run the OCaml code.

If you want to build a static library, you can use "-output-obj -o 
camlpdf.o" and then create the library yourself.

-- Alain