caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Török Edwin" <edwin+ml-ocaml@etorok.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] static linking
Date: Fri, 06 Jun 2014 19:14:27 +0300	[thread overview]
Message-ID: <5391E8E3.7030606@etorok.net> (raw)
In-Reply-To: <CADxQj2dH_biWDvDnrhho4paV7cf8tVWyepe0cLo9ujbTAJZKvA@mail.gmail.com>

On 06/06/2014 06:43 PM, Andreea Costea wrote:
> Hi,
> 
> I'm trying to build a rather big system written in Ocaml, using
> ocamlbuild. I managed to set all the needed flags nicely, so that the
> resulted binaries can run on any Unix machine,

I assume you mean any Linux machine on same architecture, or are you thinking
about something like FatELF?

> independent on their
> Ocaml distribution. However, on certain machines I have problems with
> the compatibility between the C libraries. Hence, I tried using
> "-ccopt -static"  for the -lflags and -cflags, respectively, in order
> to produce the desired statically linked binaries while building the
> project. Unfortunately, this attempt leads to the following error:
> 
> "/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `cos' with pointer
> equality in
> `/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libm.a(s_sin.o)'
> can not be used when making an executable; recompile with -fPIE and
> relink with -pie"

I don't get such an error for 'cos' on Debian, what distro do you use?

> 
> Does this mean I need to recompile the gcc libraries using -pie? Or
> does it mean I am using the wrong method to build the standalone
> executable? Any recommendation to modify the building process (i
> would prefer to use ocambuild)?
> 
> Your answer is much appreciated, Andreea

Static linking will cause troubles if you use gethostbyname or other functions from the Unix module.
Glibc gives warnings like these when linking:
/usr/lib/ocaml/libunix.a(getaddrinfo.o): In function `unix_getaddrinfo':
(.text+0x241): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/ocaml/libunix.a(gethost.o): In function `unix_gethostbyaddr':
(.text+0x1b6): warning: Using 'gethostbyaddr_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

One alternative would be to use http://www.musl-libc.org/, see here on how to do that with opam:
http://www.donadeo.net/post/2014/installing-opam-1-1-1-on-a-cenos-6-5#commentary

Note that you'll have to recompile any C library that you use, besides the already provided libc and libm, with musl-gcc.
If 4.01.0+musl+static doesn't work for you, then try 4.01.0+musl, and use -ccopt -static just when linking the final executable.

Best regards,
--Edwin

  reply	other threads:[~2014-06-06 16:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-06 15:43 Andreea Costea
2014-06-06 16:14 ` Török Edwin [this message]
2014-06-06 17:33 ` Mark Shinwell
2014-06-06 20:24 ` Gerd Stolpmann
2014-06-07  9:55   ` Andreea Costea
  -- strict thread matches above, loose matches on Subject: below --
2005-11-09 17:14 Static linking Maurizio Colucci
2005-11-09 17:28 ` [Caml-list] " Basile STARYNKEVITCH

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=5391E8E3.7030606@etorok.net \
    --to=edwin+ml-ocaml@etorok.net \
    --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).