caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Standalone executable
@ 2011-10-31 12:02 Andreea Costea
  2011-10-31 15:27 ` David Allsopp
  0 siblings, 1 reply; 5+ messages in thread
From: Andreea Costea @ 2011-10-31 12:02 UTC (permalink / raw)
  To: caml-list

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

Dear all,

For some days now, I was searching to see if there is any way you can build
an executable from an OCaml project, that can later be run from another
machine that doesn't have OCaml installed on (not even the runtime system).
Same type of Unix based OS, though.

Thanks,
Andreea

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

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

* RE: [Caml-list] Standalone executable
  2011-10-31 12:02 [Caml-list] Standalone executable Andreea Costea
@ 2011-10-31 15:27 ` David Allsopp
  2011-10-31 18:31   ` Gerd Stolpmann
  2011-11-01 15:42   ` David MENTRE
  0 siblings, 2 replies; 5+ messages in thread
From: David Allsopp @ 2011-10-31 15:27 UTC (permalink / raw)
  To: Andreea Costea, caml-list

Andreea Costea wrote:
> For some days now, I was searching to see if there is any way you can build
> an executable from an OCaml project, that can later be run from another 
> machine that doesn't have OCaml installed on (not even the runtime system).
> Same type of Unix based OS, though.

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


David



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

* RE: [Caml-list] Standalone executable
  2011-10-31 15:27 ` David Allsopp
@ 2011-10-31 18:31   ` Gerd Stolpmann
  2011-11-01 15:42   ` David MENTRE
  1 sibling, 0 replies; 5+ messages in thread
From: Gerd Stolpmann @ 2011-10-31 18:31 UTC (permalink / raw)
  To: David Allsopp; +Cc: Andreea Costea, caml-list

Am Montag, den 31.10.2011, 15:27 +0000 schrieb David Allsopp:
> Andreea Costea wrote:
> > For some days now, I was searching to see if there is any way you can build
> > an executable from an OCaml project, that can later be run from another 
> > machine that doesn't have OCaml installed on (not even the runtime system).
> > Same type of Unix based OS, though.
> 
> 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."

If you need to stay with ocamlc, you can also set the -custom option. In
this case, the whole runtime system is included into the link, and the
resulting executable only depends on the C libraries pulled in.

Gerd


> 
> 
> David
> 
> 
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
*** Searching for new projects! Need consulting for system
*** programming in Ocaml? Gerd Stolpmann can help you.
------------------------------------------------------------


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

* Re: [Caml-list] Standalone executable
  2011-10-31 15:27 ` David Allsopp
  2011-10-31 18:31   ` Gerd Stolpmann
@ 2011-11-01 15:42   ` David MENTRE
  2011-11-02  7:28     ` Andreea Costea
  1 sibling, 1 reply; 5+ messages in thread
From: David MENTRE @ 2011-11-01 15:42 UTC (permalink / raw)
  To: David Allsopp; +Cc: Andreea Costea, caml-list

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

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

* Re: [Caml-list] Standalone executable
  2011-11-01 15:42   ` David MENTRE
@ 2011-11-02  7:28     ` Andreea Costea
  0 siblings, 0 replies; 5+ messages in thread
From: Andreea Costea @ 2011-11-02  7:28 UTC (permalink / raw)
  To: David MENTRE; +Cc: caml-list

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

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

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

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

end of thread, other threads:[~2011-11-02  7:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-31 12:02 [Caml-list] Standalone executable Andreea Costea
2011-10-31 15:27 ` David Allsopp
2011-10-31 18:31   ` Gerd Stolpmann
2011-11-01 15:42   ` David MENTRE
2011-11-02  7:28     ` Andreea Costea

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