1

I was learning how to use this SDK from https://github.com/spaceships/garbled-circuits

When I finished downloading the dependencies and tried to compile one example, the error was like parse error on input '#' Here is the source code where the error came from:

import Prelude hiding (traverse)
#ifdef DEBUG
import Debug.Trace
#else
trace :: String -> a -> a
trace = flip const
traceM :: Monad m => String -> m ()
traceM _ = return ()
#endif

I guess it was because the C grammar like '#ifdef' was used in a Haskell file that caused this error, but I'd already used cabal install cipher-aes128 to download this SDK's dependencies (maybe).

6
  • How did you compile the example? #ifdef needs CPP extension which is enabled in this cabal file (github.com/spaceships/garbled-circuits/blob/master/…). I guess it should compile when you build this library using cabal before working on one of the examples.
    – snak
    Commented Jan 15, 2020 at 7:35
  • I just use ghc --make Garbler.hs. Thanks to your help, I installed all the packages in the build-depends of the library, but it still can't work and the error information is still like parse error on input '#'. Excuse of my ignorance, I have no experience in using Haskell.
    – Rookie
    Commented Jan 15, 2020 at 8:16
  • Well, it seems that the best way to build an example (for example, bit-and) is to run build.sh (github.com/spaceships/garbled-circuits/blob/master/examples/…). This script uses cabal to install all the dependencies and build the example properly.
    – snak
    Commented Jan 15, 2020 at 8:41
  • Sorry, I didn't know how to run build.sh, but I copy every line of build.sh and run it one by one. After that I try ghc --make Garbler.hs again, but the result didn't change........:(
    – Rookie
    Commented Jan 15, 2020 at 12:17
  • You don't need to run ghc --make Garbler.hs. Running all the lines in build.sh should create an executable in the current directory.
    – snak
    Commented Jan 15, 2020 at 12:45

1 Answer 1

4

Referring to the Cabal documentation,

extensions: CPP

should be added to the package description in order to enable the C pre-processor.

Source

Additionally, the language pragma:

{-# LANGUAGE CPP #-}

Also enables the language extension.

2
  • I added CPP in {-# LANGUAGE}, and the error information changed.GHC gave the following errors:Failed to load interface for 'Network.BSD'. It is a member of hidden package 'network-2.6.3.2'
    – Rookie
    Commented Jan 15, 2020 at 12:39
  • Hi, can I ask what build tool you're using? Fixing this error depends on the build tool being used
    – user12701374
    Commented Jan 15, 2020 at 17:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.