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
how to use c wrapper files in libraries
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-07-20 (14:57)
Subject: RE: [Caml-list] how to use c wrapper files in libraries
I am not familiar with this specific library.
In the general approach, you compile your c code, and package it into a library, let's say libA.a

Then while building your sndfile.cma, you should pass the option
ocamlc -a -o sndfile.cma -cclib -lA ...

A caml executable linked with your library will have also libA.a passed in the linking phase.

Using ocamlc -verbose could give you a hint to which files are missing.

Hope this helps,


-----Message d'origine-----
De : [] De la part de Aaron Bohannon
Envoyé : lundi 20 juillet 2009 16:28
À :
Objet : [Caml-list] how to use c wrapper files in libraries


I am trying to use the wrapper for libsndfile contributed by Erik de
Castro Lopo (
The wrapper code compiles just fine.  And the tests that use the OCaml
library it builds work just fine.  However, I am having a frustrating
compile-time error when I try to compile my program in a different

The wrapper code is being packaged into an OCaml library using the
following command:

ocamlc -a -o sndfile.cma -custom sndfile_stub.o sndfile.cmo \
  -ccopt -L/usr/local/lib -cclib -lsndfile

Within the same directory, the test program can be successfully compiled with:

ocamlc -o test_sndfile sndfile.cma

Within a different directory, I used:

ocamlc -o mytest -I /path/to/libsndfile-ocaml/files/   sndfile.cma

And I get:

powerpc-apple-darwin8-gcc-4.0.1: sndfile_stub.o: No such file or directory
Error while building custom runtime system

I have tried setting every path-related option I could find, and
nothing helped.  I tried reading everything I could find about
compiling and using c wrappers for OCaml, but there is a severe lack
of documentation on the topic.  In particular, I could find no example
of a c object file being given as an argument to an "ocamlc -a"
command, so I am not sure what that is supposed to do, which makes it
impossible for me to understand this error message.

I am using OCaml 3.10.1 on OS X 10.4.  Any help would be appreciated.

 - Aaron

Caml-list mailing list. Subscription management:
Beginner's list:
Bug reports:
This message and any attachments (the "message") are confidential, intended solely for the addressee(s), and may contain legally privileged information. 
Any unauthorised use or dissemination is prohibited. 
E-mails are susceptible to alteration. 
Neither Societe Generale Asset Management nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or falsified. 
Find out more about Societe Generale Asset Management's proposal on
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et susceptibles de contenir des informations couvertes par le secret professionnel.
Ce message est etabli a l'intention exclusive de ses destinataires.
Toute utilisation ou diffusion non autorisee est interdite. 
Tout message electronique est susceptible d'alteration. Societe Generale Asset Management et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie. 

Decouvrez l'offre et les services de Societe Generale Asset Management sur le site