caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: Joel Stanley <jstanley@galois.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Dynamic libs w/ Ocaml + C code under Mac OS X
Date: Tue, 05 Feb 2008 05:52:46 +0100	[thread overview]
Message-ID: <47A7EB9E.3050808@frisch.fr> (raw)
In-Reply-To: <11970BA6-EC2F-47FD-A194-BFD204057F06@galois.com>

Hi,

Joel Stanley wrote:
> The short question is: can I currently generate a shared library 
> containing natively-compiled ocaml code together with arbitrary C code 
> under Mac OS X?

I'll reply assuming you want to build a plugin that can be loaded with 
Dynlink, not a stand-alone shared library that includes the OCaml 
runtime. Otherwise let me know.

> To wit, should I be doing something other than:
> 
> $ gcc -c wrapper.c
> $ ocamlopt -dlcode -c simple.ml
> ...
> $ ocamlopt -shared -o test simple.cmx wrapper.o
> 
> or perhaps just ocamlopt -shared -o test simple.ml wrapper.c?

Both should work under Mac OS X < 10.5 on Intel. PowerPC versions are 
not supported and for 10.5, there are some issues (see below). What are 
your OS version and cpu?

> The immediate problem is that this seems to be passing the wrong 
> arguments to ld:
> 
> + ld -bundle -flat_namespace -undefined suppress -read_only_relocs 
> suppress -o 'test'  -I'/Users/jstanley/hbin/lib/ocaml' 
> '-L/Users/jstanley/hbin/lib/ocaml' 'test.startup.o' 'simple.o' 'wrapper.o'
> 
> (I'd expect to see gcc -dynamiclib (instead of bundle) here if Mac OS X 
> is supported, and without the -I switch).

I'm not very familiar with the linker of Mac OS X. In particular, I 
don't really know the differences between bundles and shared libraries.
OCaml used to produce bundles (not shared libs) for stub libraries 
(dll*.so), and I think I just decided to use the same approach.

What's wrong with the above linker invocation? Do the errors you mention 
appear with it, or only if you change the command-line to "gcc 
-dynamiclib ..."?

> which lead me to believe that simple.o is not correctly being generated 
> with position independence.

Indeed. The code generators don't produce PIC code. The Mac OS X linker 
is supposed to be able to build bundle with position-dependent code, 
using the -read_only_relocs suppress flag. This flag has been removed 
from the new linker in Leopard. Apple provides a ld_classic with the old 
behavior, but unfortunately, some libraries (like X11) seems to require 
the new linker. I think we have no good solution for Mac OS X 10.5 on 
Intel currently. Any help is welcome, of course.


-- Alain


  reply	other threads:[~2008-02-05  4:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-04 22:39 Joel Stanley
2008-02-05  4:52 ` Alain Frisch [this message]
2008-02-05 16:39   ` [Caml-list] " Joel Stanley
2008-02-05 21:00     ` Alain Frisch
2008-02-05 21:19       ` Joel Stanley
2008-02-05 21:49         ` Alain Frisch
2008-02-06  0:02           ` Joel Stanley

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=47A7EB9E.3050808@frisch.fr \
    --to=alain@frisch.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=jstanley@galois.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;
as well as URLs for NNTP newsgroup(s).