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
compiling C library wrapper
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-11-05 (22:32)
From: Aaron Bohannon <bohannon@c...>
Subject: compiling C library wrapper

I am quite confused by the whole process of compiling and installing
wrappers for C libraries.  It seems like I can get things to work OK
without really knowing what I'm doing if everything is put and built
in a single directory.  The hard part seems to be putting the right
files in the right places and getting the path arguments correct.
Then things stop working, and I have to really understand what's going
on, but the manual doesn't explain this part of the process in any

Let's say I have a library "/opt/local/lib/libfoo.a" for which I want
to build and use a (native-code) OCaml wrapper.  Here are the steps as
I understand them:

1) Write the file "foo_stubs.c" and compile it to get "foo_stubs.o".

2) Build the library "libfoo_stubs.a" by running

ar rc libfoo_stubs.a foo_stubs.o

3) Copy "libfoo_stubs.a" to its permanent location, let's say,

4) Write "foo.mli" and use it to build "foo.cmi"

5) Write "foo.ml" and use it to build "foo.cmxa" by running

ocamlopt -a -o foo.cmxa foo.ml
  -ccopt -L/opt/local/lib -cclib -lfoo
  -ccopt -L/usr/local/lib/ocaml/stubs -cclib -lfoo_stubs

6) Copy "foo.cmi" and "foo.cmxa" to their permanent location, let's
say "/usr/local/lib/ocaml/foo/"

7) Write my file "bar.ml" that needs to use the library, and compile
it by running

ocamlopt -I /usr/local/lib/ocaml/foo -o bar foo.cmxa bar.ml

However, this command ends up passing gcc the filename


which doesn't exist, so I get an error.  Where did this filename come
from?  Where did I go wrong?

 - Aaron