Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: viktor tron <viktor.tron.ml@gmail.com>
Cc: Caml Mailing List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] C libs from Ocaml libs
Date: Thu, 22 Nov 2007 18:21:20 +0100	[thread overview]
Message-ID: <4745BA90.9030104@frisch.fr> (raw)
In-Reply-To: <8cc3d8520711211035w6c9fa3a6je4622195e5a752af@mail.gmail.com>

viktor tron wrote:
> sorry, let me be very explicit then:
> 
> 0)
> I believed that the following
> creates the c object containing:
> (a) main ocaml implementation of foo (b) export API (c) C binding to API 
> (d) ocaml startup code
> 
> $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml

You are correct.

> now I create a lib
> 
> $ ar rs libfoo.a foo_caml.o
> 
> and happy ever after. Nope.
> No matter how I link it with a main c test, I get undefined symbols for startup code 
> 
> 
> $ gcc -o foo_test foo_test.c -L. -lfoo -lasmrun

What happens if you pass foo_caml.o instead of -lfoo?

Can you send me (maybe off-list) a full set of files to reproduce the 
problem?

> In fact, the following variants don't work:
> 
> 1)
> $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml
> $ ar -rs libfoo.a /sw/lib/ocaml/libasmrun.a foo_caml.o
> $ gcc -o foo_test foo_test.c -L. -lfoo

I don't think that ar supports merging libraries like that. What can be 
done is to use "ld -r" (partial linking) to produce a single object file
from libasmrun.a and foo_caml.o and then put this file in a library (or 
use it directly).

> 2)
> $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml
> $ cp /sw/lib/ocaml/libasmrun.a libfoo.a
> $ ar -rs libfoo.a foo_caml.o

Ok, that's a hack to merge one library, plus more object files into a 
library. I know it is mentioned in the OCaml manual. Personally, I would 
not recommend to do that (you'll be stuck if you need to include e.g. 
libunix.a).

> In fact ocamlopt does pretty enigmatic things in the background

Use the "-verbose" option to see what's going on.

> and ar 
> is an entire mystery with this
> copy thing.

Use "ar t" to see what's in a library.

-- Alain


  reply	other threads:[~2007-11-22 17:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-21  7:43 viktor tron
2007-11-21  9:45 ` [Caml-list] " Alain Frisch
2007-11-21 11:21   ` Matthieu Dubuget
2007-11-21 12:05     ` Alain Frisch
2007-11-21 19:48       ` Jon Harrop
2007-11-21 17:06   ` viktor tron
2007-11-21 17:33     ` Alain Frisch
2007-11-21 18:35       ` viktor tron
2007-11-22 17:21         ` Alain Frisch [this message]
2007-11-26 17:20         ` Alain Frisch
2007-11-22 16:41 RABIH.ELCHAAR

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=4745BA90.9030104@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=viktor.tron.ml@gmail.com \
    /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