From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pA27SndQ029048 for ; Wed, 2 Nov 2011 08:28:49 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AowBAC3wsE7RVaG2imdsb2JhbABDoXgBhjGBHggiAQEBCgkNBxIGIYFyAQEBAwESAiwBGx0BAwELBgUEBzsiAREBBQEcBhMaCIdgCJd7CotUgmCFHD2IcAIFCoM5hU0EiAWMD405PYN8 X-IronPort-AV: E=Sophos;i="4.69,442,1315173600"; d="scan'208";a="116069313" Received: from mail-gx0-f182.google.com ([209.85.161.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Nov 2011 08:28:43 +0100 Received: by ggnq2 with SMTP id q2so11858750ggn.27 for ; Wed, 02 Nov 2011 00:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=7O2EOtW5Z5GLGZKqH0FzdJiP4cwRxbczJdcOa6ev6HA=; b=lqdNMv93jb9cQ6lxSsLKktor2R/aJ/ko8kZHHEFqORRtR7wqlJxUDOXdBqftiY79ll CNytVNTuqulmTE+l9AUg3VtfCZbhnYSPpr4U1Rd5BZN1g29cI0yvrHDScmB/cIGlhr8t ggdqG8yepDuoeUjH3c2j/W0Ma4pyQ4Qs8H1mA= MIME-Version: 1.0 Received: by 10.150.68.24 with SMTP id q24mr4489109yba.61.1320218922206; Wed, 02 Nov 2011 00:28:42 -0700 (PDT) Received: by 10.150.200.17 with HTTP; Wed, 2 Nov 2011 00:28:41 -0700 (PDT) In-Reply-To: References: Date: Wed, 2 Nov 2011 15:28:41 +0800 Message-ID: From: Andreea Costea To: David MENTRE Cc: "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=000e0cd59204e248a304b0bb6be8 X-Validation-by: andre.costea@gmail.com Subject: Re: [Caml-list] Standalone executable --000e0cd59204e248a304b0bb6be8 Content-Type: text/plain; charset=ISO-8859-1 Thank you all for the answers. Finally i managed to make my whole project portable. I didn't manage to successfully create it since the beginning because the my makefile was still using ocamlc for certain files, and I didn't notice this before. Regards, Andreea On Tue, Nov 1, 2011 at 11:42 PM, David MENTRE wrote: > Hello, > > 2011/10/31 David Allsopp : > > Compile it with ocamlopt instead of ocamlc - Chapter 11 of the manual > (which it's a little surprising you hadn't got to, if you've been looking > for a few days)... > http://caml.inria.fr/pub/docs/manual-ocaml/manual025.html > > > > "This chapter describes the OCaml high-performance native-code compiler > ocamlopt, which compiles Caml source files to native code object files and > link these object files to produce standalone executables." > > Depending on the level of independence one might want on the > underlying system, ocamlopt alone might not me enough, as C libraries > are still dynamically linked. Option "-ccopt -static" is needed to > produce real statically linked binaries. Some parts of the OCaml > runtime may not work when statically linked, YMMV. > > Example: > > $ cat hello.ml > open Format > > let _ = printf "Hello@\n" > > > $ ocamlopt hello.ml > > $ ./a.out > Hello > > $ ldd ./a.out > linux-vdso.so.1 => (0x00007fff127e7000) > libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007faf7ca80000) > libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007faf7c87c000) > libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007faf7c4e7000) > /lib64/ld-linux-x86-64.so.2 (0x00007faf7cd2a000) > > $ ocamlopt -ccopt -static hello.ml > > $ ./a.out > Hello > > $ ldd ./a.out > not a dynamic executable > > $ file ./a.out > ./a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), > statically linked, for GNU/Linux 2.6.15, not stripped > > > Best regards, > david > --000e0cd59204e248a304b0bb6be8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thank you all for the answers. Finally i managed to make my whole project p= ortable. I didn't manage to successfully create it since the beginning= =A0 because the my makefile was still using ocamlc for certain files, and I= didn't notice this before.

Regards,
Andreea

On Tue, Nov 1, 20= 11 at 11:42 PM, David MENTRE <dmentre@linux-france.org> wrote:
Hello,

2011/10/31 David Allsopp <dra-= news@metastack.com>:
> Compile it with ocamlopt instead of ocamlc - Chapter= 11 of the manual (which it's a little surprising you hadn't got to= , if you've been looking for a few days)... http://caml.in= ria.fr/pub/docs/manual-ocaml/manual025.html
>
> "This chapter describes the OCaml high-performance native-code co= mpiler ocamlopt, which compiles Caml source files to native code object fil= es and link these object files to produce standalone executables."

Depending on the level of independence one might want on the
underlying system, ocamlopt alone might not me enough, as C libraries
are still dynamically linked. Option "-ccopt -static" is needed t= o
produce real statically linked binaries. Some parts of the OCaml
runtime may not work when statically linked, YMMV.

Example:

$ cat hello.ml
open Format

let _ =3D printf "Hello@\n"


$ ocamlopt hello.ml

$ ./a.out
Hello

$ ldd ./a.out
=A0 =A0 =A0 =A0linux-vdso.so.1 =3D> =A0(0x00007fff127e7000)
=A0 =A0 =A0 =A0libm.so.6 =3D> /lib/x86_64-linux-gnu/libm.so.6 (0x00007f= af7ca80000)
=A0 =A0 =A0 =A0libdl.so.2 =3D> /lib/x86_64-linux-gnu/libdl.so.2 (0x0000= 7faf7c87c000)
=A0 =A0 =A0 =A0libc.so.6 =3D> /lib/x86_64-linux-gnu/libc.so.6 (0x00007f= af7c4e7000)
=A0 =A0 =A0 =A0/lib64/ld-linux-x86-64.so.2 (0x00007faf7cd2a000)

$ ocamlopt -ccopt -static hel= lo.ml

$ ./a.out
Hello

$ ldd ./a.out
=A0 =A0 =A0 =A0not a dynamic executable

$ file ./a.out
./a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux),
statically linked, for GNU/Linux 2.6.15, not stripped


Best regards,
david

--000e0cd59204e248a304b0bb6be8--