Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting CPP Macros

Tags:

haskell

ghc

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

like image 834
crockeea Avatar asked Dec 02 '25 02:12

crockeea


1 Answers

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

like image 120
vivian Avatar answered Dec 03 '25 21:12

vivian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!