In the cabal file I specify the GHC options -Wall and -O2:
name: Test
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.8
executable Test
hs-source-dirs: src
main-is: Test.hs
build-depends: base >=4.8 && <4.10
ghc-options: -Wall -O2
When I compile the program Test.hs:
data Color = Red | Green | Blue
foo :: Color -> Int
foo Red = 0
foo Green = 1
-- foo Blue is intentionally missing!!
I get the error:
Preprocessing executable 'Test' for Test-0.1.0.0...
[1 of 1] Compiling Main ( src/Test.hs, .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0/build/Test/Test-tmp/Main.o )
/home/user/Projekte/HaskellTutorials/Test/src/Test.hs:1:1: error:
The IO action ‘main’ is not defined in module ‘Main’
-- While building package Test-0.1.0.0 using:
/home/user/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --build
dir=.stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0 build exe:Test --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
The error about the missing main action is not the problem.
Look at the text at the end of the second last line:
build exe:Test --ghc-options " -ddump-hi -ddump-to-file"
Why do I not see my GHC options -Wall -O2? (I fear, I did some stupid little mistake ...)
PS:
stack version is: Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1
LTS: 8.17
The options -ddump-hi -ddump-to-file are being passed by Stack to Cabal. Cabal then adds them to the options specified in the .cabal file before passing them along to GHC.
If you run Stack with:
stack -v --cabal-verbose
and search through the output, you'll see that your options are in fact being passed to GHC.
As #epsilonhalbe noted, GHC isn't complaining about the more minor issues when it discovers that main is missing, so if you add:
main = undefined
to the bottom of your program, you'll get the warnings you're expecting.
Related
It seems I might need to add some 'packages' to the nix dependencies, though I'm not sure how to determine which packages (besides a tedious web search for each lm,lrt...)?
stack install
Building all executables for `sodiumSierraStrawberry' once. After a successful build of all of them, only specified executables will be rebuilt.
sodiumSierraStrawberry-0.1.0.0: configure (exe)
Configuring sodiumSierraStrawberry-0.1.0.0...
sodiumSierraStrawberry-0.1.0.0: build (exe)
Preprocessing executable 'sodiumSierraStrawberry' for sodiumSierraStrawberry-0.1.0.0..
Building executable 'sodiumSierraStrawberry' for sodiumSierraStrawberry-0.1.0.0..
[1 of 2] Compiling Paths_sodiumSierraStrawberry ( .stack-work/dist/x86_64-linux-nix/Cabal-2.4.0.1/build/sodiumSierraStrawberry/autogen/Paths_sodiumSierraStrawberry.hs, .stack-work/dist/x86_64-linux-nix/Cabal-2.4.0.1/build/sodiumSierraStrawberry/sodiumSierraStrawberry-tmp/Paths_sodiumSierraStrawberry.o )
[2 of 2] Compiling Prompt ( src/Prompt.hs, .stack-work/dist/x86_64-linux-nix/Cabal-2.4.0.1/build/sodiumSierraStrawberry/sodiumSierraStrawberry-tmp/Prompt.o )
Linking .stack-work/dist/x86_64-linux-nix/Cabal-2.4.0.1/build/sodiumSierraStrawberry/sodiumSierraStrawberry ...
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lm
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lrt
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lutil
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -ldl
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lgmp
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lm
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lrt
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -ldl
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lpthread
/nix/store/5vyv136pqs75pj0b8vcpdyc03dmn9p0n-binutils-2.30/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
-- While building package sodiumSierraStrawberry-0.1.0.0 using:
/home/chris/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.3 --builddir=.stack-work/dist/x86_64-linux-nix/Cabal-2.4.0.1 build exe:sodiumSierraStrawberry --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
cabal file:
-- This file has been generated from package.static.yaml by hpack version 0.28.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: dc5d80120403b39adcd93487e3eb7b084fcc8abb48bc9c23eaaa9dbc7c48cb06
cabal-version: >= 1.10
name: sodiumSierraStrawberry
version: 0.1.0.0
author: Chris Stryczynski
maintainer: Chris Stryczynski
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
ChangeLog.md
executable sodiumSierraStrawberry
main-is: Prompt.hs
other-modules:
Paths_sodiumSierraStrawberry
hs-source-dirs:
src
default-extensions: LambdaCase
ghc-options: -Wall -O2 -static -threaded -main-is Prompt
cc-options: -static
ld-options: -static -pthread
build-depends:
MissingH
, aeson
, base
, bytestring
, directory
, filepath
, optparse-applicative
, pretty-simple
, safe
, split
, stm
, string-conversions
, text
, thyme
, time
default-language: Haskell2010
In this particular case I was able to solve it by adding:
nix:
packages:
- glibc.static
- gmp5.static
However, I'm still not sure how I can determine the relationship between these flags (lm, lrt etc) to the actual packages.
I would like to always use the "-Wall -Werror" options when building with stack (executing stack build) but adding these flags to ghc-options in package.yaml does nothing. I would also like to avoid passing the --pedantic flag to stack build. Here's the config files:
package.yaml
...
executables:
XYZ-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -Wall
- -Werror
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- XYZ
...
XYZ.cabal
...
executable XYZ-exe
main-is: Main.hs
hs-source-dirs:
app
ghc-options: -Wall -Werror -threaded -rtsopts -with-rtsopts=-N
...
The "-Wall -Werror" flags are specified in ghc-options but as-if ignored when building. This is the output for stack build:
stack build
Building all executables for `XYZ' once. After a successful build of all of
them, only specified executables will be rebuilt.
XYZ-0.1.0.0: configure (lib + exe)
Configuring XYZ-0.1.0.0...
XYZ-0.1.0.0: build (lib + exe)
Preprocessing library for XYZ-0.1.0.0..
Building library for XYZ-0.1.0.0..
[ 1 of 105] Compiling Data.List.Extras ( src\Data\List\Extras.hs, .stack-
work\dist\e626a42b\build\Data\List\Extras.o )
... the rest is omitted, all succeed ...
And here's the output for stack build --pedantic
stack build --pedantic
Building all executables for `HStat' once. After a successful build of all of them, only specified executables will be rebuilt.
HStat-0.1.0.0: configure (lib + exe)
Configuring HStat-0.1.0.0...
HStat-0.1.0.0: build (lib + exe)
Preprocessing library for HStat-0.1.0.0..
Building library for HStat-0.1.0.0..
[ 1 of 105] Compiling Data.List.Extras ( src\Data\List\Extras.hs, .stack-work\dist\e626a42b\build\Data\List\Extras.o )
src\Data\List\Extras.hs:4:1: error: [-Wunused-imports, -Werror=unused-imports]
The import of ‘Data.Maybe’ is redundant
except perhaps to import instances from ‘Data.Maybe’
To import instances alone, use: import Data.Maybe()
|
4 | import Data.Maybe
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
This works as expected - src\Data\List\Extras.hs indeed does have an unused Data.Maybe import. What am I doing wrong?
The ghc-options flags had to be separately defined in the library part of package.yaml:
library:
source-dirs: src
ghc-options:
- -Wall
- -Werror
- -fwarn-incomplete-uni-patterns
Doing that solved the issue.
I'm trying to use the req package (http://hackage.haskell.org/package/req) in a Haskell project, with stack.
So far, I've done stack new my-project, stack setup, stack build and stack exec my-project-exe all fine.
Have added req to the cabal file like so:
name: my-project
version: 0.1.0.0
synopsis: Short description of your package
homepage: https://github.com/githubuser/#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example#example.com
copyright: 2017 Author name here
category: Web
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Lib
build-depends: base >= 4.7 && < 5
, req -- THIS IS THE LINE IVE ADDED
default-language: Haskell2010
executable my-project-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, my-project
default-language: Haskell2010
test-suite my-project-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, my-project
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
source-repository head
type: git
location: https://github.com/githubuser/my-project
And finally, cut and paste the example from the req readme into src/Lib.hs, changing the function name like so:
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Lib
( someFunc
) where
import Control.Exception (throwIO)
import Network.HTTP.Req
import Data.Aeson
-- Just make your monad stack an instance of MonadHttp in your application
-- and start making requests, enjoy automatic connection sharing.
instance MonadHttp IO where
handleHttpException = throwIO
someFunc :: IO ()
someFunc = do
let payload = object
[ "foo" .= (10 :: Int)
, "bar" .= (20 :: Int) ]
-- One function, full power and flexibility.
r <- req POST -- method
(https "httpbin.org" /: "post") -- safe by construction URL
(ReqBodyJson payload) -- use built-in options or add your own
jsonResponse -- specify how to interpret response
mempty -- query params, headers, explicit port number, etc.
print (responseBody r :: Value)
And now stack build is erroring:
%> stack build
basement-0.0.4: configure
basement-0.0.4: build
zlib-0.6.1.2: configure
aeson-1.1.2.0: download
zlib-0.6.1.2: build
network-2.6.3.2: configure
th-lift-instances-0.1.11: download
aeson-1.1.2.0: configure
aeson-1.1.2.0: build
th-lift-instances-0.1.11: configure
th-lift-instances-0.1.11: build
th-lift-instances-0.1.11: copy/register
aeson-1.1.2.0: copy/register
Progress: 5/28
-- While building package network-2.6.3.2 using:
/tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/setup --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 configure --with-ghc=/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/bin/ghc --with-ghc-pkg=/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/bin/ghc-pkg --user --package-db=clear --package-db=global --package-db=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/pkgdb --libdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/lib --bindir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/bin --datadir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/share --libexecdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/libexec --sysconfdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/etc --docdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/doc/network-2.6.3.2 --htmldir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/doc/network-2.6.3.2 --haddockdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/doc/network-2.6.3.2 --dependency=base=base-4.9.1.0 --dependency=bytestring=bytestring-0.10.8.1 --dependency=unix=unix-2.7.2.1
Process exited with code: ExitFailure 1
Logs have been written to: /home/liam/code/forecast-compare/.stack-work/logs/network-2.6.3.2.log
[1 of 2] Compiling Main ( /tmp/stack7830/network-2.6.3.2/Setup.hs, /tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/Main.o )
[2 of 2] Compiling StackSetupShim ( /home/liam/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/StackSetupShim.o )
Linking /tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/setup ...
Configuring network-2.6.3.2...
configure: WARNING: unrecognized options: --with-compiler
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... /usr/bin/gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/tmp/stack7830/network-2.6.3.2':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
-- While building package zlib-0.6.1.2 using:
/home/liam/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/liam/code/forecast-compare/.stack-work/logs/zlib-0.6.1.2.log
Configuring zlib-0.6.1.2...
Building zlib-0.6.1.2...
Preprocessing library zlib-0.6.1.2...
/usr/bin/ld: .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
linking .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make.o failed (exit code 1)
command was: /usr/bin/gcc .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make.o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_utils.o -o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make -fno-PIE -fno-stack-protector -lz -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/bytestring-0.10.8.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/bytestring-0.10.8.1 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/deepseq-1.4.2.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/deepseq-1.4.2.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/array-0.5.1.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/array-0.5.1.1 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -lgmp -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -lm -lrt -ldl -lpthread
-- While building package basement-0.0.4 using:
/home/liam/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/liam/code/forecast-compare/.stack-work/logs/basement-0.0.4.log
Configuring basement-0.0.4...
Building basement-0.0.4...
Preprocessing library basement-0.0.4...
/usr/bin/ld: .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
linking .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make.o failed (exit code 1)
command was: /usr/bin/gcc .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make.o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_utils.o -o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make -fno-PIE -fno-stack-protector -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -lgmp -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -lm -lrt -ldl -lpthread
Any help much appreciated!
This issue has been plaguing users of Arch Linux for a few months. It appears to be related to the ncurses library, and possibly due to Arch Linux dynamically linking Haskell packages, whilst most (all?) other distros use static linking.
The current work around involves using the ghc-build: nopie option for the stack ghc version, and installing ncurses5-compat-libs from the AUR.
If you wish to set this globally, you can set it in your ~/.stack/config.yaml, so it applies to all projects you build with stack.
A bug report is currently open here, and some related discussion can be found on the arch forums or the stack github.
For me deleting ~/.stack and using
stack setup --ghc-build=ncurses6
and adding
ghc-build: ncurses6
to
~/.stack/config.yaml
resolved this.
Addendum:
ghc-build: tinfo6
and
stack setup --ghc-build=tinfo6
worked even better for me.
After running:
stack new my-project
cd my-project
stack setup
stack build
I would like to add the Conduit library as a dependency.
I edited the generated, via stack new, stack.yaml to have:
extra-deps:
- conduit-1.2.10
Then, I modified the my-project.cabal from:
executable my-project-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, my-project
default-language: Haskell2010
to:
executable my-project-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, my-project
, conduit
default-language: Haskell2010
When I try to stack build the following:
$cat app/Main.hs
module Main where
import Conduit
import Lib
main :: IO ()
main = someFunc
It fails:
$stack build
mtl-2.2.1: using precompiled package
primitive-0.6.1.0: using precompiled package
stm-2.4.4.1: using precompiled package
transformers-compat-0.5.1.4: using precompiled package
exceptions-0.8.3: using precompiled package
mmorph-1.0.9: using precompiled package
transformers-base-0.4.4: using precompiled package
monad-control-1.0.1.0: using precompiled package
lifted-base-0.2.3.10: using precompiled package
resourcet-1.1.9: using precompiled package
conduit-1.2.10: configure
conduit-1.2.10: build
conduit-1.2.10: copy/register
my-project-0.1.0.0: configure (lib + exe)
Configuring my-project-0.1.0.0...
my-project-0.1.0.0: build (lib + exe)
Preprocessing library my-project-0.1.0.0...
[1 of 1] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'my-project-exe' for my-project-0.1.0.0...
[1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/my-project-exe/my-project-exe-tmp/Main.o )
/Users/kevinmeredith/Workspace/conduit_sandbox/my-project/app/Main.hs:3:1: error:
Failed to load interface for ‘Conduit’
Use -v to see a list of the files searched for.
Completed 12 action(s).
-- While building package my-project-0.1.0.0 using:
/Users/kevinmeredith/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:my-project exe:my-project-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
How can I properly add conduit?
When adding a library to a stack project, do I need to edit both the stack.yaml and/or my-project.cabal?
If you look at the haddocks for conduit, notice the module you want to import is not Conduit, it is Data.Conduit.
The Conduit module comes from the conduit-combinators package. If that is the package you would like to use instead, adjust your cabal file as follows and import Conduit as before:
executable my-project-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, my-project
, conduit-combinators
default-language: Haskell2010
The differences between the packages are summarized below (this is taken from the project's readme).
conduit-combinators: provides a large number of common functions built-in
conduit: defines the core datatypes and primitive functions
conduit-extra: adds support for many common low-level operations
Side note: You don't need to make any changes to your stack.yaml file as both of these packages are available on stackage.
After connect to .cabal file some package(for example text) and after build project throw Exception: Process exited with code: ExitFailure 1".
For building project, I'm using haskell-stack, command: stack build in terminal. (I'm using MacOS Capitan)
Some line .cabal file:
executable Real-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, Real
, text
default-language: Haskell2010
Without(text package) all working.
Full Error:
"Real-0.1.0.0: unregistering (dependencies changed)
Real-0.1.0.0: configure
Configuring Real-0.1.0.0...
Real-0.1.0.0: build
Preprocessing library Real-0.1.0.0...
[1 of 1] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64- osx/Cabal-1.22.4.0/build/Lib.o )
In-place registering Real-0.1.0.0...
Preprocessing executable 'Real-exe' for Real-0.1.0.0...
<command line="">: cannot satisfy -package-id text-1.2.1.3- 3718968f98d5614ccdc45c27d4e8b0a1
(use -v for more information)
-- While building package Real-0.1.0.0 using:
/Users/ximet/.stack/setup-exe-cache/setup-Simple-Cabal-1.22.4.0-x86_64-osx-ghc-7.10.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.4.0/ build lib:Real exe:Real-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1"
Such errors may be due to an out of date package cache. ghc-pkg recache run at the command line may help.
Failing that, executing stack --no-system-ghc --install-ghc build instead of the usual stack command line will just tell stack to not use the installed libs at all, which may also help.