caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Whitington <john@coherentgraphics.co.uk>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Building a mixed C / OCaml static library to be used from C
Date: Thu, 22 Aug 2013 18:34:38 +0100	[thread overview]
Message-ID: <52164BAE.3080509@coherentgraphics.co.uk> (raw)

Hi,

I have the following recipe to build a static library of C functions 
from a mixed ocaml / c codebase. The idea is that the final linking step 
to build target 'test' won't require any special flags:


CAMLBASE = /Users/john/.opam/4.00.1/lib/

mklib: cpdflib.mli cpdflib.ml cpdflibwrapper.c
	ocamlfind ocamlc -package cpdf cpdflib.mli;
	ocamlfind ocamlopt -package cpdf -c cpdflib.ml;
	ocamlfind ocamlc cpdflibwrapper.c;
	ocamlfind ocamlopt -I $(CAMLBASE)cpdf -I $(CAMLBASE)camlpdf \
           -output-obj -o cpdflib.o \
           unix.cmxa bigarray.cmxa camlpdf.cmxa cpdf.cmxa cpdflib.cmx;
	ar -x $(CAMLBASE)camlpdf/libcamlpdf_stubs.a;
	ar -x $(CAMLBASE)ocaml/libasmrun.a;
	ar cr cpdflib.a *.o

test:   cpdflib.a cpdflibtest.c
	cc cpdflibtest.c cpdflib.a -o test\
           -L $(CAMLBASE)ocaml -lbigarray -lunix

clean:
	rm __.SYMDEF\ SORTED *.o *.cmx *.cmi *.a test


(Here, cpdflib.ml, cpdflib.mli and cpdflibwrapper.c form the C interface 
to the OCaml functions. cpdflibtest.c calls caml_startup and then any 
caml functions it likes).

This works. However, I'm having trouble getting rid of "-L 
$(CAMLBASE)ocaml -lbigarray -lunix" -- i'd like the person linking with 
my cpdflib.a not to need any dependencies at all.

When I add two more lines

         ar -x $(CAMLBASE)ocaml/bigarray.a;
         ar -x $(CAMLBASE)ocaml/unix.a;

in the obvious place and remove "-L $(CAMLBASE)ocaml -lbigarray -lunix" 
when building the example, the linking fails, not being able to find the 
symbols for unix and bigarray. ar -t confirms that bigarray.o, unix.o 
and unixlabels.o are in the created cpdflib.a

Any ideas, or another recipe altogether?

Thanks,

-- 
John Whitington
Director, Coherent Graphics Ltd
http://www.coherentpdf.com/


             reply	other threads:[~2013-08-22 17:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 17:34 John Whitington [this message]
2013-08-22 22:24 ` Gerd Stolpmann
2013-08-27 13:12   ` 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=52164BAE.3080509@coherentgraphics.co.uk \
    --to=john@coherentgraphics.co.uk \
    --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;
as well as URLs for NNTP newsgroup(s).