How to use #ifdef WIN32

Spencer Janssen sjanssen at cse.unl.edu
Thu Dec 20 22:16:21 EST 2007


On Thursday 20 December 2007 18:37:15 Jim Burton wrote:
> I want to switch code on the OS but this always goes through to the #else
> (on windows or elsewhere):
>
> {-# OPTIONS -cpp #-}
> #ifdef WIN32
> main = putStrLn "hello windows"
> #else
> main = putStrLn "hello something else"
> #endif
>
> Does this depend on a Makefile setting WIN32, or should there be something
> predefined?
>
> Thanks,

If you're using Cabal, something like this should work:

    if os(win32)
        cpp-options: -DWIN32


Cheers,
Spencer Janssen



More information about the Glasgow-haskell-users mailing list