caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: cartan@cartan.de
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How to link libraries with C parts (Bug?)
Date: Tue, 12 Jun 2001 11:19:04 +0900	[thread overview]
Message-ID: <20010612111904Y.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <lkvgm6ah7r.fsf@pc022.bln.elmeg.de>

From: Nils Goesche <cartan@cartan.de>

> I have got a strange problem: I am writing an Ocaml library
> which uses some C code.  However, when I try to link this library to
> an application, I get consistently some strange error (see below).  I
> guess I am building the library incorrectly, but I have tried a
> gazillion of variations to no avail.

[...]

> That's it.  Now I build it:
> 
> $ ocamlc.opt -c mylib.mli
> 
> $ ocamlopt.opt -c mylib.ml
> 
> $ cc -c -DNATIVE_CODE -I /usr/local/lib/ocaml mylibcall.c -o mylibcall.o
> 
> $ ocamlopt.opt -a mylibcall.o -o mylib.cmxa mylib.cmx

In order to use the autolink feature of ocaml, you should put your C
object inside a library. That is:

$ ar cf libmylibcall.a mylibcall.o
$ ocamlopt.opt -a -cclib -lmylibcall -o mylib.cmxa mylib.cmx

Then the rest should work correctly
> 
> Compiling it:
> 
> $ ocamlopt.opt -c -I /home/nils/src/caml/bug/mylib myapp.ml
> 
> And linking:
> 
> $ ocamlopt.opt -I /home/nils/src/caml/bug/mylib \
>       -ccopt -L/home/nils/src/caml/bug/mylib  mylib.cmxa \
>       -o myapp myapp.cmx

You don't even need the -ccopt -L... : all directories marked by -I
are automatically added in the link.

Cheers,

Jacques Garrigue
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-06-12  2:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-08 19:45 Nils Goesche
2001-06-12  2:19 ` Jacques Garrigue [this message]
2001-06-12 13:54   ` Nils Goesche

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=20010612111904Y.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=cartan@cartan.de \
    /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).