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] newbie question: How to do conditional compilation?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-09-18 (08:06)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] newbie question: How to do conditional compilation?

On Mon, Sep 17, 2001 at 09:02:28PM -0700, Gao katie wrote:

> Can anyone tell me how to do conditional compilation in Ocaml?
> #ifdef DEBUG
> ...
> #else
> ...
> #endif

You can use camlp4.

Compile either with 
   ocamlc -pp "camlp4o pa_ifdef.cmo"
or with
   ocamlc -pp "camlp4o pa_ifdef.cmo -DDEBUG"

In your code, you can then use "ifdef DEBUG ... else ... end" in
position of expression, or "ifdef ... end" in position of structure
item (toplevel phrase, if you prefer). You can also use "define"
(but without parameters: "define DEBUG", not "define DEBUG xxx")

Another solution is to use /lib/cpp, the C preprocessor.  I think that
you can use it in only one command with the ocamlc parameter -pp:
   ocamlc -pp "/lib/cpp"
   ocamlc -pp "/lib/cpp -DDEBUG"


Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr