caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David MENTRE <dmentre@linux-france.org>
To: David Allsopp <dra-news@metastack.com>
Cc: Andreea Costea <andre.costea@gmail.com>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Standalone executable
Date: Tue, 1 Nov 2011 16:42:22 +0100	[thread overview]
Message-ID: <CAC3Lx=YR9qRnH4kJ2HLqPOq0b9SThFku4L-=t9AuTsaPYWrCzw@mail.gmail.com> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9C24C5FB7@Remus.metastack.local>

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

  parent reply	other threads:[~2011-11-01 15:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 12:02 Andreea Costea
2011-10-31 15:27 ` David Allsopp
2011-10-31 18:31   ` Gerd Stolpmann
2011-11-01 15:42   ` David MENTRE [this message]
2011-11-02  7:28     ` Andreea Costea

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='CAC3Lx=YR9qRnH4kJ2HLqPOq0b9SThFku4L-=t9AuTsaPYWrCzw@mail.gmail.com' \
    --to=dmentre@linux-france.org \
    --cc=andre.costea@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=dra-news@metastack.com \
    /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).