Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] newbie question: How to do conditional compilation?
Hi,

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

1/
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")

2/
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"

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/

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