From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id F1AB97F919 for ; Fri, 6 Jun 2014 18:14:32 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of edwin+ml-ocaml@etorok.net) identity=pra; client-ip=62.113.205.31; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="edwin+ml-ocaml@etorok.net"; x-sender="edwin+ml-ocaml@etorok.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of edwin+ml-ocaml@etorok.net designates 62.113.205.31 as permitted sender) identity=mailfrom; client-ip=62.113.205.31; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="edwin+ml-ocaml@etorok.net"; x-sender="edwin+ml-ocaml@etorok.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@mx.etorok.net designates 62.113.205.31 as permitted sender) identity=helo; client-ip=62.113.205.31; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="edwin+ml-ocaml@etorok.net"; x-sender="postmaster@mx.etorok.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiAFAJbokVM+cc0f/2dsb2JhbABZgw1Sg0XBEwGBBhZ1hAMBAQQBIx04AgQLCxIGAgIFEwMLAgIJAwIBAgE3DhMIAog2DAmtBXeFBZozEQaBKo1GFoJfgUyKK4tlhAqTQIM/Og X-IPAS-Result: AiAFAJbokVM+cc0f/2dsb2JhbABZgw1Sg0XBEwGBBhZ1hAMBAQQBIx04AgQLCxIGAgIFEwMLAgIJAwIBAgE3DhMIAog2DAmtBXeFBZozEQaBKo1GFoJfgUyKK4tlhAqTQIM/Og X-IronPort-AV: E=Sophos;i="4.98,990,1392159600"; d="scan'208";a="78476584" Received: from mx.etorok.net ([62.113.205.31]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Jun 2014 18:14:32 +0200 Received: by mx.etorok.net (OpenSMTPD) with ESMTP id 7149c7df; for ; Fri, 6 Jun 2014 19:14:28 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=etorok.net; h= message-id:date:from:mime-version:to:references:in-reply-to :content-type:content-transfer-encoding; s=ml; l=2446; bh=gY5LGs vsnr6fDpuSYs53RgHs3V0=; b=ZAy4utW5LdAxbr9JU3YhKy35y9htrNLc0aFbSy pwWXdazBdGLJ2z6uQzTyb4rpFnxkiaqDxLMoRwPtqForUuU+96+eTEqsva1VSukg 5nL7WJnaNJ8BMolaFogk3boz0X9zc76NqN4aSleXcPSLx/qY6lEqcNwhFAa/fKRO z6nrY= Received: by mx.etorok.net (OpenSMTPD) with ESMTPSA id a49beb2f; TLS version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO; for ; Fri, 6 Jun 2014 19:14:28 +0300 (EEST) Message-ID: <5391E8E3.7030606@etorok.net> Date: Fri, 06 Jun 2014 19:14:27 +0300 From: =?UTF-8?B?VMO2csO2ayBFZHdpbg==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Icedove/30.0 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] static linking 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