caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dan Benjamin <dbenjamin@janestreet.com>
To: David Sheets <sheets@alum.mit.edu>
Cc: Bruno Deferrari <utizoc@gmail.com>, O Caml <caml-list@inria.fr>
Subject: Re: [Caml-list] Static linking via Ctypes?
Date: Tue, 25 Mar 2014 13:55:48 -0400	[thread overview]
Message-ID: <CACKEwpa4ypJQUHgsYzG1ftTCAjf5FX6rGsrok-UuDqNiRdif2Q@mail.gmail.com> (raw)
In-Reply-To: <CAAWM5TwF6th2i0jMQMm_Bi0Q_j5zpSnGAaP4LsWVQY=4J=HAbA@mail.gmail.com>

That does work, thanks very much.  Are there plans to add anything
similar to Ctypes?

On Tue, Mar 25, 2014 at 11:24 AM, David Sheets <sheets@alum.mit.edu> wrote:
> On Tue, Mar 25, 2014 at 3:11 PM, Dan Benjamin <dbenjamin@janestreet.com> wrote:
>> I am passing -force_load, as well as --whole-archive (in case that
>> makes a difference), and I have the following situation:
>>
>> - readelf -s shows that the function that I wish to call exists in the
>> executable
>> - running the executable results in Dl.DL_error("undefined symbol")
>> for the same function, corresponding to the line of code where I call
>> Foreign.foreign.
>>
>> Am I going about this wrongly?
>
> I did
>
> <https://github.com/dsheets/ocaml-unix-unistd/blob/master/lib/unix_unistd_stubs.c#L61>
>
> and
>
> <https://github.com/dsheets/ocaml-unix-unistd/blob/master/lib/ctypes/unix_unistd.ml#L32>
>
> to require a static link without stub generation in addition to
> ocamlmklib on the .ml and .o files.
>
> Unfortunately, this is not very portable (or sane). I believe that
> <https://github.com/ocamllabs/ocaml-ctypes/issues/96> may be related.
>
> Hope this helps,
>
> David
>
>> On Tue, Mar 25, 2014 at 11:04 AM, Bruno Deferrari <utizoc@gmail.com> wrote:
>>> On Tue, Mar 25, 2014 at 11:54 AM,  <dbenjamin@janestreet.com> wrote:
>>>> I'm using Ctypes to interface with a dynamic library, but in addition to the
>>>> interface provided the library I have some helper functions (written in C,
>>>> against the same library) that I'd also like to call via Ctypes.  Is there any
>>>> way to achieve this via static linking or am I required to build another
>>>> shared object?
>>>>
>>>
>>> Static linking works. I was in this same situation yesterday, and
>>> adding the .o files that were generated from C sources to the linking
>>> step did the trick.
>>>
>>> If you are trying to link a .a file, you may have to pass the
>>> -force_load option to the linker to force it to include it, otherwise
>>> it may see that none of the symbols there are being referenced
>>> directly and decide to not include it (this happened to me when using
>>> clang in OSX).
>>>
>>>> --
>>>> 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
>>>
>>>
>>>
>>> --
>>> BD
>>
>> --
>> 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

  reply	other threads:[~2014-03-25 17:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-25 14:54 dbenjamin
2014-03-25 15:04 ` Bruno Deferrari
2014-03-25 15:11   ` Dan Benjamin
2014-03-25 15:24     ` David Sheets
2014-03-25 17:55       ` Dan Benjamin [this message]
2014-03-25 21:19         ` Jeremy Yallop
2014-03-25 21:37           ` Milan Stanojević
2014-03-25 23:14             ` Jeremy Yallop
2014-03-26 16:24               ` Travis Brady
2014-03-26 17:17                 ` Daniel Bünzli
2014-03-26 17:25               ` Milan Stanojević
2014-03-25 15:10 ` Daniel Bünzli

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=CACKEwpa4ypJQUHgsYzG1ftTCAjf5FX6rGsrok-UuDqNiRdif2Q@mail.gmail.com \
    --to=dbenjamin@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=sheets@alum.mit.edu \
    --cc=utizoc@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).