caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@college-de-france.fr>
To: BOBOT Francois <Francois.BOBOT@cea.fr>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Dynamic link of C library
Date: Sun, 13 Feb 2022 17:55:34 +0100	[thread overview]
Message-ID: <CAH=h3gGJgTMuk4jC4sRf5x0UjtsSOiZjmYkrw_i5+hbrwHEj8Q@mail.gmail.com> (raw)
In-Reply-To: <3496160576413589fd508d9af3902f195cf2f1ee.camel@cea.fr>

[-- Attachment #1: Type: text/plain, Size: 2112 bytes --]

On Fri, Feb 11, 2022 at 7:18 PM BOBOT Francois <Francois.BOBOT@cea.fr>
wrote:

> Hi everyone,
>
>         I'm a little lost with some binding. Usually I bind statically
> C library in OCaml libraries (except for C libraries already present on
> the system). It works well for all the targets (bytecode, native static
> .cmxa, native dynamic .cmxs) by keeping the C library in the OCaml
> library. Usually one just need to be sure that libfoo.a is compiled
> with -fPic (which is not usual). However static linking lose the
> advantage of a C library with the *L*GPL licence (no?). So I'm lost
> between everything we have:
>
>    - .cmxs needs ld to be able to find the dynamic C library, libfoo.so
>    - there is the stublibs directory, but it is only for bytecode and
> files are prefixed by dll instead of lib so ld can't find them.
>    - There is no directory to install dynamic C library in opam, no
> LD_LIBRARY_PATH set
>    - -dllpath requires to know the install directory during compilation
>
>
> -dllpath is usually the chosen solution but hardcoding path makes build
> cache less useful, and dune knows the install directory only at the
> end. Is there an elegant solution I haven't seen or some of our tools
> need to be modified?
>

This problem with Unix-style shared libraries is not specific to OCaml: you
run into the same issues with a program entirely written in C, if I'm not
mistaken.

Popular wisdom says that .so files must be installed in /usr/lib or
/usr/local/lib or some other public place advertised in /etc/ld.so.conf.
(With semantic versioning, if applicable.)  Some applications install their
own .so files in a specific directory, then consist in a shell script that
sets LD_LIBRARY_PATH before running the main executable.

I'm not convinced OCaml tools should try to implement a different
behavior.  In particular, I would object to OPAM setting LD_LIBRARY_PATH in
the environment to point to a directory owned by the user: it looks like a
security risk.

Kind regards,

- Xavier Leroy



>
> Best,
>
> --
> François
>

[-- Attachment #2: Type: text/html, Size: 2756 bytes --]

  reply	other threads:[~2022-02-13 16:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11 18:18 BOBOT Francois
2022-02-13 16:55 ` Xavier Leroy [this message]
2022-02-16  7:32   ` BOBOT Francois
2022-03-11 14:48 ` BOBOT Francois

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='CAH=h3gGJgTMuk4jC4sRf5x0UjtsSOiZjmYkrw_i5+hbrwHEj8Q@mail.gmail.com' \
    --to=xavier.leroy@college-de-france.fr \
    --cc=Francois.BOBOT@cea.fr \
    --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).