caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Pablo Polvorin" <pablo.polvorin@gmail.com>
To: "Joel Reymont" <joelr1@gmail.com>
Cc: "Caml List" <caml-list@inria.fr>
Subject: Re: [Caml-list] OCaml and C code in a dynamic library
Date: Thu, 29 Mar 2007 20:26:59 -0300	[thread overview]
Message-ID: <1ffe809c0703291626g4b385bd2qee9f9b5d72e3b95b@mail.gmail.com> (raw)
In-Reply-To: <2A0CAD37-6509-4FD8-A5C0-D704C7E17E2A@gmail.com>

Hi Joel,
i recently make a dynamic library including c++ wrappers to an ocaml
module, to be loaded as a SCA component by apache tuscany.
The first problem was that i have a 64b architecture, and in order to
link against libcamlrun in shared mode, a recompilation of the runtime
with -fPIC flag was necessary. I called the resulting library
libcamlrun_shared, to not confuse it with the original one.

Also you have to initialize the ocaml runtime from whiting you
library.., and for my best knowledge it is necessary to pass the path
to you .so to the caml_main function, like:

#define LIB_DIR "/home/pablo/ocaml/tproject/deploy/TuscanyCalculator"
  static char *argv[] = {
    LIB_DIR "/libTuscanyCalculatorImpl.so",
    LIB_DIR "/libTuscanyCalculatorImpl.so",
    NULL
  };
  caml_main (argv);

The way that work for my is to compile the c code with -c -fPIC flags,
 compile the ocaml modules also with -c , and then link all the object
codes together with  ocamlc -linkall -custom -cclib "-fPIC -shared
... and include the libraries you need ( -lcamlrun_shared  -ltermcap
in my system)

I think the best is to look at the makefile of the ocaml module for
the aol server http://www.crystalballinc.com/vlad/software/

or the apache mod_ocaml
http://merjis.com/developers/mod_caml , a lite more complex makefile.

also, look at these previous post in this area:
http://caml.inria.fr/pub/ml-archives/caml-list/2002/09/0d8daa135bd30302f1ebf30daf9a0ed9.en.html
http://caml.inria.fr/pub/ml-archives/caml-list/2002/01/44d30c5454106646098bf00977c66796.en.html
http://caml.inria.fr/pub/ml-archives/caml-list/2001/12/e9e89dadd773729481bf8446f1b73b64.en.html

and also the manual pages
http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html

regards,
pablo.




2007/3/29, Joel Reymont <joelr1@gmail.com>:
> Has anyone succeeded in wrapping OCaml code in a dynamic library for
> use in C?
>
> I can build a static OCaml library without any problems but when I
> try to package that and some other C code in a dynamic library I get
> errors like this on Mac OSX:
>
> /usr/bin/ld: ./libfib.a(fibcaml.o) has local relocation entries in
> non-writable section (__TEXT,__text)
>
> 	Thanks, Joel
>
> --
> http://wagerlabs.com/
>
>
>
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


-- 
Pablo Polvorin


  reply	other threads:[~2007-03-29 23:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-29 22:22 Joel Reymont
2007-03-29 23:26 ` Pablo Polvorin [this message]
2007-04-03  8:15   ` [Caml-list] " Richard Jones

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=1ffe809c0703291626g4b385bd2qee9f9b5d72e3b95b@mail.gmail.com \
    --to=pablo.polvorin@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=joelr1@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;
as well as URLs for NNTP newsgroup(s).