Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Tom Ridge <tom.j.ridge+caml@googlemail.com>
To: caml-list <caml-list@inria.fr>
Subject: Fwd: [Caml-list] Using OCaml from C
Date: Tue, 10 Sep 2013 18:21:31 +0100	[thread overview]
Message-ID: <CABooLwN+2d1hzpoAH-xta_GCjxMV7fyG7-XZxU0ZD6MwycsV5w@mail.gmail.com> (raw)
In-Reply-To: <CABooLwPmKWc0KAOZ2weuwAfBbXUUKhBa7rxJ+=LASVL-0KeBmA@mail.gmail.com>

Just to make a final report:

Following Gerd and Stephane, I used ocamlfind -verbose to print the
options ocamlfind was passing to cc. After tidying, my Makefile now
looks like:

--

SHELL=bash

OCAMLPATH=/home/tr61/.opam/4.00.1/lib


all:
  ocamlfind ocamlc -package core,str -linkpkg -thread -output-obj -o
modcaml.o pqueue.ml mod.ml
  ocamlc -c modwrap.c
  rm -f mod.a
  ar rcs mod.a modcaml.o modwrap.o
  cc -o prog main.c mod.a -L$(OCAMLPATH)/bin_prot
-L$(OCAMLPATH)/variantslib -L$(OCAMLPATH)/num -L$(OCAMLPATH)/sexplib
-L$(OCAMLPATH)/fieldslib -L$(OCAMLPATH)/oUnit -L$(OCAMLPATH)/pa_ounit
-L$(OCAMLPATH)/res -L$(OCAMLPATH)/core_kernel -L$(OCAMLPATH)/core
-L$(OCAMLPATH)/ocaml/threads -L$(OCAMLPATH)/ocaml -lcamlstr
-lcore_stubs -lrt -lcore_kernel_stubs -lnums -lbin_prot_stubs
-lbigarray -lthreads -lunix -lpthread -lunix -lcamlrun
-I$(OCAMLPATH)/ocaml -lm  -ldl -lcurses -lpthread

--

which is better (e.g. no need for -pthread argument to cc, no need for
-Xlinker --allow-multiple-definition), although a bit verbose (but the
options were determined automatically, so this is a big time win).

Thanks



On 10 September 2013 15:21, Stéphane Glondu <steph@glondu.net> wrote:
> Le 10/09/2013 15:30, David Allsopp a écrit :
>>> Your calls to cp, ar and your use of -custom look suspicious. But it is
>>> difficult to be more helpful without a concrete testcase.
>>
>> They're exactly as in the manual and are correct for compiling with ocamlc for static linking with C code. The cp and ar calls are necessary to set-up the static library (which should use libcamlrun.a as a starting point) - see #19.8 (the example in question), #19.7.4, #19.7.5 and #19.1.3 in the manual.
>
> Well, that doesn't make them more right.
>
> With the example of the manual, the following works and is much saner:
>
>   ocamlc -output-obj -o modcaml.o mod.ml
>   ocamlc -c modwrap.c
>   ar rcs mod.a modcaml.o modwrap.o
>   cc -o prog main.c mod.a -L`ocamlc -where` -lcamlrun -lm -ldl -lcurses
>
> Copying libcamlrun.a around and fiddling with it also works and avoids
> -L`ocamlc -where` -lcamlrun but it is just insane, as insane as
> embedding the C standard library and runtime into third-party static
> libraries.
>
>
> Cheers,
>
> --
> Stéphane
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  parent reply	other threads:[~2013-09-10 17:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 12:21 Tom Ridge
2013-09-10 12:41 ` David Allsopp
2013-09-10 13:21   ` Gerd Stolpmann
2013-09-10 13:09 ` Stéphane Glondu
2013-09-10 13:30   ` David Allsopp
2013-09-10 13:59     ` Tom Ridge
2013-09-10 14:21     ` Stéphane Glondu
     [not found]       ` <CABooLwPmKWc0KAOZ2weuwAfBbXUUKhBa7rxJ+=LASVL-0KeBmA@mail.gmail.com>
2013-09-10 17:21         ` Tom Ridge [this message]
2013-09-10 17:27           ` Fwd: " Adrien Nader
2013-09-12  9:51             ` Stéphane Glondu

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=CABooLwN+2d1hzpoAH-xta_GCjxMV7fyG7-XZxU0ZD6MwycsV5w@mail.gmail.com \
    --to=tom.j.ridge+caml@googlemail.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