From: David Scott <scott.dj@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Simplifying link steps when making shared libraries containing OCaml (possibly OSX specific)
Date: Tue, 10 Nov 2015 15:41:22 +0000 [thread overview]
Message-ID: <CAG_esB3RoRh5n35riX81UCGacLu-C1g9Y7zgLYmMckwJaZn9_g@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2363 bytes --]
Hi,
I've packaged up some OCaml code with a C shim and made a shared library (a
".so" file) on OSX. It's all working fine! However the build steps I'm
using are a bit verbose -- I wonder if anyone knows how to simplify them?
I'm building all the objects and then using a custom linker invocation, see
below. Notice that I'm tediously listing all the stubs for all my ocamlfind
packages-- this seems like it could be simplified somehow.
```
PACKS="cstruct lwt io-page...."
WHERE=$(ocamlc -where)
cd _build
ocamlfind ocamlopt -thread -package "$PACKS" -c ../c_callbacks.ml -o
c_callbacks.cmx
ocamlfind ocamlopt -thread -linkpkg -package "$PACKS" -output-obj -o
camlcode.o c_callbacks.cmx
gcc -I ${WHERE} -g -Wall -Wextra -c ../c_shim.c -o c_shim.o
gcc -shared camlcode.o c_shim.o -ldl -lm -L ${WHERE} \
$(ocamlfind query cstruct)/cstruct.a \
$(ocamlfind query cstruct)/libcstruct_stubs.a \
$(ocamlfind query io-page)/io_page.a \
$(ocamlfind query io-page)/io_page_unix.a \
$(ocamlfind query io-page)/libio_page_unix_stubs.a \
$(ocamlfind query lwt.unix)/liblwt-unix_stubs.a \
$(ocamlfind query lwt.unix)/lwt-unix.a \
$(ocamlfind query lwt.unix)/lwt.a \
$(ocamlfind query threads)/libthreadsnat.a \
-lasmrun -lbigarray -lunix -o my_shared_library.so
```
I tried following Jeremy's inverted ctypes example here:
https://github.com/yallop/ocaml-ctypes-inverted-stubs-example/blob/ff713bc9a9159828b2c3d7e6661f7ba76855e8b7/Makefile#L29
This looks good because it relies on ocamlfind + ocamlopt to do the right
thing but unfortunately it fails on my OSX box because it produces a
"bundle" (with "-bundle" linker option) rather than a shared library (with
a "-shared" linker option):
When ocamlopt builds the ctypes-inverted-stubs-example .so it's one of
these:
```
$ file _build/libxmlm.so
_build/libxmlm.so: Mach-O 64-bit bundle x86_64
```
which then causes failures which look like
```
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file
'../_build/test/../libxmlm.so' for architecture x86_64
```
When I do it by hand, I can replace "-bundle" with "-shared" which results
in:
```
$ file _build/libxmlm.so
_build/libxmlm.so: Mach-O 64-bit dynamically linked shared library x86_64
```
which then links ok.
Any tips greatly appreciated!
Thanks,
--
Dave Scott
[-- Attachment #2: Type: text/html, Size: 3450 bytes --]
next reply other threads:[~2015-11-10 15:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-10 15:41 David Scott [this message]
2015-11-10 18:20 ` John Whitington
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=CAG_esB3RoRh5n35riX81UCGacLu-C1g9Y7zgLYmMckwJaZn9_g@mail.gmail.com \
--to=scott.dj@gmail.com \
--cc=caml-list@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