[Haskell-beginners] Fwd: using Shake to compile c++

Roger Mason rmason at mun.ca
Sat Jul 8 14:51:58 UTC 2017


David McBride <toad3k at gmail.com> writes:

> Sorry this should have been sent to the list.
>
> ---------- Forwarded message ----------
> From: David McBride <toad3k at gmail.com>
> Date: Sat, Jul 8, 2017 at 8:49 AM
> Subject: Re: [Haskell-beginners] using Shake to compile c++
> To: Roger Mason <rmason at mun.ca>
>
>
> There's three errors here.  pkg-config is an IO action and thus in
> order to use its output, you must use <- instead of a let binding.
> Then you must choose what you want to save from that command.  You
> could get the exit result, stderr or stdout or both stdout and stderr.
> We want stdout.  And lastly, Stdout is parameterized over a type a,
> and you have to decide which.
>
> You can either do the following
>
> Stdout i <- cmd "pkg-config glib-2.0 --cflags"
> () <- cmd "c++ -c" [c] "-o" [out] "-MMD -MF" [m] [i :: String]
>
> Or you can enable ScopedTypeVariables and go
> Stdout (i :: String) <- cmd "pkg-config glib-2.0 --cflags"
>
> I don't really understand why Stdout is parameterized, rather than
> just being forced to be a string like Stdin, that's a question for the
> shake authors.

For the record, I have currently

"objects//*.o" %> \out -> do
        let c = dropDirectory1 $ out -<.> "cxx"
        let m = out -<.> "m"
        Stdout i <- cmd "pkg-config glib-2.0 --cflags"
        need i
        () <- cmd "c++ -c" [c] "-o" [out] "-MMD -MF" [m] [i :: String]
        needMakefileDependencies m

and get

Build.hs:31:59: error:
    * Couldn't match type `[Char]' with `Char'
      Expected type: String
        Actual type: [FilePath]
    * In the expression: i :: String
      In the 7th argument of `cmd', namely `[i :: String]'
      In a stmt of a 'do' block:
        () <- cmd "c++ -c" [c] "-o" [out] "-MMD -MF" [m] [i :: String]

I thank you very much for your help but it is clear that the use of
Shake requires rather more Haskell knowledge than is implied by the
docs.  Given that this is just the easy part of the build the prospects
for early success look scant so I will move on and try something else.

Thanks again,
Roger


More information about the Beginners mailing list