Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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:  FAQ:
To unsubscribe, mail  Archives: