English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] bytecode apps without stdlib/pervasives
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-11-17 (16:14)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] bytecode apps without stdlib/pervasives

On Nov 15, 2005, at 23:45, Jonathan Roewen wrote:

> Hi,
> I have a simple ML file (test.ml):
> external raise : exn -> 'a = "%raise";;
> raise End_of_file;;
> so I can check how the compiler does things (like if predefined ocaml
> symbols are still present without stdlib present), and compile as:
> ocamlc -nostdlib -nopervasives test.ml, which generates a.out.
> when I run it, I get error: "-bash: ./a.out: cannot execute binary
> file" (btw, generates expected behabiour without those flags)
> why can't it execute it? can we only use -nostdlib as long as we
> provide our own pervasives module?

Note that a.out is still a valid bytecode file:
   ocamlrun ./a.out

What happens is that ocamlc tries to create an executable bytecode file,
by prepending the standard header (#!/usr/local/bin/ocamlrun) to your
bytecode file.  But it can't find this header because you have specified
-nostdlib, thus preventing it from looking in its library directory.

It explicitely ignores the "file not found" error, I'm not sure why.

What you can do is provide your own header file, named "camlheader", and
placed in one of the directories searched by ocamlc.  If you don't give
any -I option, this has to be the current directory:

$ echo '#!/bin/echo foo' >camlheader
$ ocamlc -nostdlib -nopervasives test.ml
$ ./a.out
foo ./a.out

-- Damien