caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: "'Aaron Bohannon'" <bohannon@cis.upenn.edu>, <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] compiling C library wrapper
Date: Thu, 5 Nov 2009 23:09:38 -0000	[thread overview]
Message-ID: <000001ca5e6d$0d6a0aa0$283e1fe0$@metastack.com> (raw)
In-Reply-To: <c413fcb70911051432l5d28918cq55b95272efb6330@mail.gmail.com>

Aaron Bohannon wrote: 
> 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
> detail.

Have a look at ocamlmklib in the manual - if it's available on your platform
then it nicely hides away a lot of this.

<snip - steps 1-4 are fine>
> 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

This command will also build foo.cmx, foo.a and foo.o

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

You should also copy foo.a to this directory which should fix the problem.
foo.cmxa contains information required by OCaml but the actual code is in
foo.a (as it's been natively compiled). Similarly, .cmx files contain
information which ocamlopt needs but the actual code is in .o (or .obj)
files. For native code, it's a code idea to copy the .cmx files too as it
allows ocamlopt to do some inlining (I think that's right...)

> 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

This should now work without error.


David



  reply	other threads:[~2009-11-05 23:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-05 22:32 Aaron Bohannon
2009-11-05 23:09 ` David Allsopp [this message]
2009-11-05 23:38   ` [Caml-list] " Aaron Bohannon
2009-11-07 12:25     ` Richard Jones
2009-11-07 16:34       ` Aaron Bohannon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000001ca5e6d$0d6a0aa0$283e1fe0$@metastack.com' \
    --to=dra-news@metastack.com \
    --cc=bohannon@cis.upenn.edu \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).