Haskell stack fails with error message "unsatisfied constraints" - haskell

When building my project, I'm receiving a cryptic error
C:\Users\T60\Dropbox\note-build>stack build
note-build-0.1.0.0: build
Preprocessing library note-build-0.1.0.0...
setup-Simple-Cabal-1.22.5.0-ghc-7.10.3.exe: unsatisfied constraints
-- While building package note-build-0.1.0.0 using:
C:\stack_root\setup-exe-cache\i386-windows\setup-Simple-Cabal-1.22.5.0-ghc-7.10.3.exe --builddir=.stack-work\dist\95439361 build lib:note-build exe:note-build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
It seems to be caused by adding filepath to the executable depends section of my cabal file. My Main.hs file uses System.FilePath, and without the line in my cabal file it fails, but adding it gives me this error. Prior to trying to use the filepath module, the project would build.
executable note-build
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, filepath
, directory
, note-build
default-language: Haskell2010
What does this error mean, and am I putting the dependency in the wrong place in my cabal file?
Update: I ran the build using the -v flag, and it revealed that I'd absentmindedly substituted + for ++.
C:\Users\T60\Dropbox\note-build\app\Main.hs:20:31: #(stack_9kewhubnl5WIl89fhd1ea2:Stack.Build.Execute src/Stack\Build\Execute.hs:911:67)
2016-07-07 22:08:24.020516: [warn] No instance for (Num FilePath) arising from a use of `+' #(stack_9kewhubnl5WIl89fhd1ea2:Stack.Build.Execute src/Stack\Build\Execute.hs:911:67)
2016-07-07 22:08:24.051760: [warn] In the first argument of `normalise', namely `(y + "/")' #(stack_9kewhubnl5WIl89fhd1ea2:Stack.Build.Execute src/Stack\Build\Execute.hs:911:67)
2016-07-07 22:08:24.067386: [warn] In the expression: normalise (y + "/") #(stack_9kewhubnl5WIl89fhd1ea2:Stack.Build.Execute src/Stack\Build\Execute.hs:911:67)
2016-07-07 22:08:24.129886: [warn] In an equation for `y_norm': y_norm = normalise (y + "/").
So the fix was easy enough, but should I consider this a potential issue with stack that I had to use verbose output to see what seems like a simple type error?

Related

Haskeline throws linking error in stack build

I'm trying to build haskell project via stack build command, but it throws excepton:
-- While building package %some secret project name%-0.1.0.0 (scroll up to its section to see the error) using:
/home/%some secret username%/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0 build lib:%some secret project name% exe:%exe name% --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
Also it outputs following error in log file:
Linking .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/%secret name%/%secret name% ...
/usr/bin/ld.gold: error: cannot find -ltinfo
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/haskeline-0.8.2/libHShaskeline-0.8.2.a(Terminfo.o)(.text..LsmG9_info+0x76): error: undefined reference to 'set_curterm'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/haskeline-0.8.2/libHShaskeline-0.8.2.a(Terminfo.o)(.text..LsmG9_info+0xcc): error: undefined reference to 'set_curterm'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/haskeline-0.8.2/libHShaskeline-0.8.2.a(Terminfo.o)(.text..LsmG9_info+0x147): error: undefined reference to 'set_curterm'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/haskeline-0.8.2/libHShaskeline-0.8.2.a(Terminfo.o)(.text..LsmG9_info+0x1bb): error: undefined reference to 'set_curterm'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/terminfo-0.4.1.4/libHSterminfo-0.4.1.4.a(Base.o)(.text..Lr5WM_info+0xb2): error: undefined reference to 'tigetnum'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/terminfo-0.4.1.4/libHSterminfo-0.4.1.4.a(Base.o)(.text..Lr5WN_info+0xb2): error: undefined reference to 'tigetflag'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/terminfo-0.4.1.4/libHSterminfo-0.4.1.4.a(Base.o)(.text..Lr5WO_info+0xb2): error: undefined reference to 'tigetstr'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/terminfo-0.4.1.4/libHSterminfo-0.4.1.4.a(Base.o)(.text..Ls64w_info+0x354): error: undefined reference to 'tparm'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/terminfo-0.4.1.4/libHSterminfo-0.4.1.4.a(Base.o)(.text..Ls66r_info+0x129): error: undefined reference to 'setupterm'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/terminfo-0.4.1.4/libHSterminfo-0.4.1.4.a(Base.o)(.text..Ls66r_info+0x22a): error: undefined reference to 'del_curterm'
/home/messieurme/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/terminfo-0.4.1.4/libHSterminfo-0.4.1.4.a(Base.o)(.text..Ls68h_info+0x141): error: undefined reference to 'tputs'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
My code haven't any errors in .hs files. Also I can invoke any function (even main) via stack ghciand it works fine.
After some researches I found that if I'll remove haskeline from dependencies in %project name%.cabal file, stack build will execute witout any problems.
I use haskeline only in app/main.hs and my code is from this site. Here it is
import System.Console.Haskeline
main :: IO ()
main = runInputT defaultSettings loop
where
loop :: InputT IO ()
loop = do
minput <- getInputLine "% "
case minput of
Nothing -> return ()
Just "quit" -> return ()
Just input -> do outputStrLn $ "Input was: " ++ input
loop
Here is part of .cabal file where I'm adding haskeline:
executable hi
hs-source-dirs: app
main-is: %Some secret main name%.hs
ghc-options: -Wall -Werror -threaded -rtsopts -with-rtsopts=-N
build-depends: base >= 4.9 && < 5
, %extra deps%
, haskeline
default-language: Haskell2010
Version of haskeline doesn't matter. I tried to set previous versions and error occured with each of them.
I tried to google problem, but it seems that nobody faced it before or it's too trivial to ask about.
I'm using linux mint, maybe it impacts somehow.
I fully reinstalled stack but problem is still with me. Deleting temporary files like .stack-work within project also didn't help
The problem were due to the missing libtinfo-dev. Once I had library installed the problem disappeared. Thanks to the answer in comments

Compile only one target from a stack project with multiple targets in the cabal file

I have a similar setup like this SO question.
However I'm working with stack and not directoly with cabal:
stack.yaml
Test.cabal
src/FirstExe
src/SecondExe
The stack file is minimal
resolver: lts-8.17
packages:
- '.'
The file Test.cabal has 2 executables:
name: Test
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.8
executable FirstExe
hs-source-dirs: src
main-is: FirstExe.hs
build-depends: base >=4.8 && <4.10
executable SecondExe
hs-source-dirs: src
main-is: SecondExe.hs
build-depends: base >=4.8 && <4.10
The src/FirstExe.hs compiles successfully:
main :: IO ()
main = putStrLn "FirstExe compiles nicely"
The src/SecondExe.hs has an error:
main :: IO ()
main = "SecondExe gives compiler error" -- putStrLn is missing ...
(Note: The goal of this error is to see, when stack builds the SecondExe.)
When I do a stack ide targets I get
Test:exe:FirstExe
Test:exe:SecondExe
Now I want to compile only the first target FirstExe without compiling the second and without changing
the Test.cabal file. In reallity I will switch between the 2 executables.
According to the Haskell Tool Stack documentation it should
be possible
I tried two possibilies:
stack build :FirstExe
stack build Test:exe:FirstExe
In both cases it compiles the second executable too!
Test-0.1.0.0: configure (exe)
Configuring Test-0.1.0.0...
Test-0.1.0.0: build (exe)
Preprocessing executable 'FirstExe' for Test-0.1.0.0...
Preprocessing executable 'SecondExe' for Test-0.1.0.0...
[1 of 1] Compiling Main ( src/SecondExe.hs, .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0/build/SecondExe/SecondExe-tmp/Main.o )
/home/roland/Projekte/HaskellTutorials/Test/src/SecondExe.hs:2:8: error:
* Couldn't match expected type `IO ()' with actual type `[Char]'
* In the expression: "SecondExe gives compiler error"
In an equation for `main': main = "SecondExe gives compiler error"
-- While building package Test-0.1.0.0 using:
/home/roland/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0 build exe:FirstExe exe:SecondExe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
What am I doing wrong?

haskell stack exception missing dependencies

I want to add the bound library to my package dependencies;
The project is completely fresh initialized with stack new.
The entry in the cabal file looks like this:
executable DependendLambda-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, DependendLambda
, bound
default-language: Haskell2010
I get the following error message:
While constructing the build plan, the following exceptions were encountered:
In the dependencies for DependendLambda-0.1.0.0:
bound must match -any, but the stack configuration has no specified
version (latest applicable is 1.0.7)
Recommended action:
try adding the following to your extra-deps in /home/MyProject/stack.yaml:
- bound-1.0.7
You may also want to try the 'stack solver' command
Plan construction failed.
Warning: build failed, but optimistically launching GHCi anyway
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Using main module: 1. Package `DependendLambda' component exe:DependendLambda-exe with main-is file: /home/MyProject/app/Main.hs
Configuring GHCi with the following packages: DependendLambda
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
<command line>: cannot satisfy -package bound
(use -v for more information)
When I add the dependency to extra-deps it is still failing:
While constructing the build plan, the following exceptions were encountered:
In the dependencies for bound-1.0.7:
binary-0.8.3.0 must match >=0.5 && <0.8 (latest applicable is 0.7.6.1)
comonad-5 must match >=3 && <5 (latest applicable is 4.3)
transformers-0.5.2.0 must match >=0.2 && <0.5 (latest applicable is 0.4.3.0)
needed due to DependendLambda-0.1.0.0 -> bound-1.0.7
Plan construction failed.
Warning: build failed, but optimistically launching GHCi anyway
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Using main module: 1. Package `DependendLambda' component
exe:DependendLambda-exe with main-is file: /home/MyProject/app/Main.hs
Configuring GHCi with the following packages: DependendLambda
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
<command line>: cannot satisfy -package bound-1.0.7
(use -v for more information)
The stack solver command didn't help either ... what am I missing?
Thanks for your help!

Building project dependent on gtk2hs fails on lts-7.8 and later

Building project dependent on glib fails on lts-7.8 and later after Cabal becomes 1.24.1.0.
Steps to reproduce
Add glib to a project's .cabal file
build-depends: base
, gtktest
, glib
Run following commands
stack install gtk2hs-buildtools
stack build
Result
The following error occurred
...
[debug] Ignoring package Cabal due to wanting version 1.24.1.0 instead of 1.24.0.0
#(Stack\Build\Installed.hs:196:5)
...
-- While building package glib-0.13.4.1 using:
C:\Users\foo\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.1\bin\ghc.EXE --make -odir C:\Users\foo\AppData\Local\Temp\stack5512\glib-0.13.4.1\.stack-work\dist\b7fec021\setup -hidir C:\Users\foo\AppData\Local\Temp\stack5512\glib-0.13.4.1\.stack-work\dist\b7fec021\setup -i -i. -package=Cabal-1.24.0.0 -clear-package-db -global-package-db -package-db=C:\sr\snapshots\a78c6a89\pkgdb C:\Users\foo\AppData\Local\Temp\stack5512\glib-0.13.4.1\Setup.hs -o C:\Users\foo\AppData\Local\Temp\stack5512\glib-0.13.4.1\.stack-work\dist\b7fec021\setup\setup
Process exited with code: ExitFailure 1
Logs have been written to: C:\Users\foo\Documents\Files\Haskell\gtktest\.stack-work\logs\glib-0.13.4.1.log
[1 of 1] Compiling Main ( C:\Users\foo\AppData\Local\Temp\stack5512\glib-0.13.4.1\Setup.hs, C:\Users\foo\AppData\Local\Temp\stack5512\glib-0.13.4.1\.stack-work\dist\b7fec021\setup\Main.o )
C:\Users\foo\AppData\Local\Temp\stack5512\glib-0.13.4.1\Setup.hs:8:29: error:
Couldn't match expected type ‘Distribution.Simple.UserHooks.UserHooks’
with actual type ‘Cabal-1.24.1.0:Distribution.Simple.UserHooks.UserHooks’
NB: Cabal-1.24.1.0:Distribution.Simple.UserHooks.UserHooks’
is defined in ‘Distribution.Simple.UserHooks’
in package ‘Cabal-1.24.1.0’
‘Distribution.Simple.UserHooks.UserHooks’
is defined in ‘Distribution.Simple.UserHooks’
in package ‘Cabal-1.24.0.0’
In the first argument of ‘defaultMainWithHooks’, namely
gtk2hsUserHooks’
In the expression: defaultMainWithHooks gtk2hsUserHooks
In an equation for ‘main’:
main = defaultMainWithHooks gtk2hsUserHooks
I thought that Cabal-1.24.0.0 in the ghc-8.0.1 global package was causing problems, and succeeded building it after installing Cabal-1.24.1.0 in ghc 's global package.
However, this method is difficult for beginners and I do not think the right solution. How is the correct way to solve it?
Stack version
Version 1.2.0, Git revision 123819b7d65df2ad7fe63fb5eb39a98536acb5f3 (4055 commits) x86_64 hpack-0.14.0

Haskell stack not building test executable

Background
I'm building a logfile parser in Haskell. I'm using stack to build it. Running the stack build command works happily and my project compiles. Running stack test, however, produces the following error:
parser-test: executable not found
I see the the following warning above the error message but I don't know how to avoid the redirect to which it refers.
Warning: output was redirected with -o, but no output will be generated because there is no Main module.
Relevant files
I haven't written any tests yet so the test file is as it was created by stack new. My cabal file looks like this:
...
category: Executable
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: LogParser
build-depends: base >= 4.7 && < 5
, attoparsec
, bytestring
, old-locale
, time
default-language: Haskell2010
executable parser-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, attoparsec
, bytestring
, old-locale
, time
, parser
default-language: Haskell2010
test-suite parser-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, attoparsec
, bytestring
, hspec
, hspec-attoparsec
, old-locale
, time
, parser
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
source-repository head
type: git
...
I presume I'm missing something but I can't find where what I'm missing is documented.
Desired behaviour
I should see the Test suite not yet implemented message outlined in the stack documentation.
The content of the test/Spec.hs file from the template is:
main :: IO ()
main = putStrLn "Test suite not yet implemented"
You can see this content at commercialhaskell/stack-templates in new-template.hsfiles.
I'm not sure where the module ParserSpec where line comes from (as brought up in the Github issue), but it's not part of the template. On my system, stack new bar && cd bar && stack test succeeds.
As to the reason behind the Main module requirement: it comes from the Cabal library, and as I understand it was added due to limitations in other compilers Cabal supports. In other words, GHC could technically allow this code to compile, but Cabal does not pass in those arguments to remain compatible with other compilers.

Resources