caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] static linking
@ 2014-06-06 15:43 Andreea Costea
  2014-06-06 16:14 ` Török Edwin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andreea Costea @ 2014-06-06 15:43 UTC (permalink / raw)
  To: caml-list

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

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, 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"

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

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] static linking
  2014-06-06 15:43 [Caml-list] static linking Andreea Costea
@ 2014-06-06 16:14 ` Török Edwin
  2014-06-06 17:33 ` Mark Shinwell
  2014-06-06 20:24 ` Gerd Stolpmann
  2 siblings, 0 replies; 6+ messages in thread
From: Török Edwin @ 2014-06-06 16:14 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] static linking
  2014-06-06 15:43 [Caml-list] static linking Andreea Costea
  2014-06-06 16:14 ` Török Edwin
@ 2014-06-06 17:33 ` Mark Shinwell
  2014-06-06 20:24 ` Gerd Stolpmann
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Shinwell @ 2014-06-06 17:33 UTC (permalink / raw)
  To: Andreea Costea; +Cc: caml-list

On 6 June 2014 16:43, Andreea Costea <andre.costea@gmail.com> wrote:
> 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, 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.

My advice would be to reconsider carefully why you want to statically
link.  Read this:
http://www.akkadia.org/drepper/no_static_linking.html

The most important point is: if you're using a glibc or eglibc-based
system, you should not statically link the C library.  (The advice is
probably similar for other platforms.)

You don't say exactly which libraries are causing the compatibility
problems, but if it is indeed glibc, then one solution might be to
spin up some virtual machines to use when you need to build your
system against older versions.

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] static linking
  2014-06-06 15:43 [Caml-list] static linking Andreea Costea
  2014-06-06 16:14 ` Török Edwin
  2014-06-06 17:33 ` Mark Shinwell
@ 2014-06-06 20:24 ` Gerd Stolpmann
  2014-06-07  9:55   ` Andreea Costea
  2 siblings, 1 reply; 6+ messages in thread
From: Gerd Stolpmann @ 2014-06-06 20:24 UTC (permalink / raw)
  To: Andreea Costea; +Cc: caml-list

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

I'd strongly recommend against linking statically libc and other core
system libraries (e.g. libm, libdl, librt, ...). This creates more
problems than it solves. Instead, only link those libraries statically
that are causing the trouble. Unfortunately, this isn't directly
possible by just passing a linker option, but there is a solution by
rewriting the linker arguments:

See the attached script gcc_wrapper.sh (I'm using this or a derivative,
depending on the system). Just tell ocaml to use this script as C
compiler:

ocamlopt ... -cc ./gcc_wrapper.sh ...

Also set the environment variable STATIC_LIBS to the names of the
libraries you'd like to link statically (e.g. STATIC_LIBS="pcre z" would
select libpcre and libz).

The script here is only activated when there is an

  -o <name>.opt

argument. You may want to modify this part. (I'm just taking the version
of the script from the plasma project; some more work is required to
make it fully generic.)

Gerd


Am Freitag, den 06.06.2014, 23:43 +0800 schrieb Andreea Costea:
> 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, 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"
> 
> 
> 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
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: gcc_wrapper.sh --]
[-- Type: application/x-shellscript, Size: 767 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] static linking
  2014-06-06 20:24 ` Gerd Stolpmann
@ 2014-06-07  9:55   ` Andreea Costea
  0 siblings, 0 replies; 6+ messages in thread
From: Andreea Costea @ 2014-06-07  9:55 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: caml-list

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

Mark and Gerd, thank you both for your replies and suggestions. Indeed
glibc (/lib64/libc.so.6) was the one causing troubles.
For short time, I shall try the script Gerd provided, and perhaps for long
term we should consider building our system without the core libs
statically linked.

Thanks again,
Andreea



On Sat, Jun 7, 2014 at 4:24 AM, Gerd Stolpmann <info@gerd-stolpmann.de>
wrote:

> I'd strongly recommend against linking statically libc and other core
> system libraries (e.g. libm, libdl, librt, ...). This creates more
> problems than it solves. Instead, only link those libraries statically
> that are causing the trouble. Unfortunately, this isn't directly
> possible by just passing a linker option, but there is a solution by
> rewriting the linker arguments:
>
> See the attached script gcc_wrapper.sh (I'm using this or a derivative,
> depending on the system). Just tell ocaml to use this script as C
> compiler:
>
> ocamlopt ... -cc ./gcc_wrapper.sh ...
>
> Also set the environment variable STATIC_LIBS to the names of the
> libraries you'd like to link statically (e.g. STATIC_LIBS="pcre z" would
> select libpcre and libz).
>
> The script here is only activated when there is an
>
>   -o <name>.opt
>
> argument. You may want to modify this part. (I'm just taking the version
> of the script from the plasma project; some more work is required to
> make it fully generic.)
>
> Gerd
>
>
> Am Freitag, den 06.06.2014, 23:43 +0800 schrieb Andreea Costea:
> > 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, 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"
> >
> >
> > 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
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
> --
> ------------------------------------------------------------
> Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
> My OCaml site:          http://www.camlcity.org
> Contact details:        http://www.camlcity.org/contact.html
> Company homepage:       http://www.gerd-stolpmann.de
> ------------------------------------------------------------
>
>

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Static linking
  2005-11-09 17:14 Static linking Maurizio Colucci
@ 2005-11-09 17:28 ` Basile STARYNKEVITCH
  0 siblings, 0 replies; 6+ messages in thread
From: Basile STARYNKEVITCH @ 2005-11-09 17:28 UTC (permalink / raw)
  To: Maurizio Colucci; +Cc: caml-list


Hello All,

Le Wed, Nov 09, 2005 at 06:14:00PM +0100, Maurizio Colucci écrivait/wrote:
> I gave an executable, compiled with ocamlopt, to a friend of mine, and
> his system complained about a missing library (libgtkgl-2.0.so.1).
> This library is not available for his linux distribution. How can I
> compile the program by embedding the library in the executable? 

If your system has a static version of libgtkgl (eg on Debian/Sid the
libgtkgl2.0-dev package provides /usr/lib/libgtkgl-2.0.a) you could
pass the "-cclib /usr/lib/libgtkgl-2.0.a" option (without the quotes)
to ocamlopt.

But for this particular library, I believe things are much less simple
in practice, because I think that gtkgl depends upon many other shared
libraries.

You might also consider passing the "-ccopt -static" option to
ocamlopt linking.

Again, GTKGL is not supposed (as GTK) to be statically linked...

Maybe the simplest solution is to find the suitable (rpm or other)
package of libgtkgl for your user!

Regards.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile(at)starynkevitch(dot)net 
8, rue de la Faïencerie, 92340 Bourg La Reine, France


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-07  9:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-06 15:43 [Caml-list] static linking Andreea Costea
2014-06-06 16:14 ` Török Edwin
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

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).