Reputation: 21811
I'm hacking around with someone else's code. They have several macros defined in a .h
file (no code, just macros), and these macros are used in several Haskell files. What I'm missing is the step which allows this compilation. When I try to compile the Haskell file, I just get errors on the missing/undefined macros. Is there a GHC option that will use macros defined in a header file? I'm trying to do the same with GHCi.
I did attempt to just rename the .h
file to .hs
and import it in the files that use the macros, but I am apparently not allowed to export macros (and they are not exported automatically).
How can I use these macros when compiling with GHC(i)?
Upvotes: 3
Views: 565
Reputation: 1434
Add the CPP pragma to the top of your haskell file and add a #include foo.h
line to the haskell file. The C preprocessor will expand the macros for you.
See [1] for options like -Dsymbol=value
which will define a macro for all the files that are compiled with that invocation of ghc
.
[1] https://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html
Upvotes: 3