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.
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.
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.
I am trying out c2hs, and wanted to compile a small example of a shared library with Cabal to get started.
I have the following relevant section of the cabal file test.cabal:
executable libtest.so
hs-source-dirs: src
main-is: Dummy.hs
other-extensions: ForeignFunctionInterface
build-depends: base
default-language: Haskell2010
ghc-options: -no-hs-main -threaded
build-tools: c2hs
Then the source. src/Dummy.hs:
import Test
main :: IO ()
main = return
In the file src/Test.chs
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign
import Foreign.C
module Android where
And then when I try to compile (cabal configure && cabal build -v) I get the following error message:
Component build order: executable 'libtest.so'
creating dist/build
creating dist/build/autogen
Building test-0.1.0.0...
Preprocessing executable 'libtest.so' for test-0.1.0.0...
Building executable libtest.so...
creating dist/build/libtest.so
creating dist/build/libtest.so/libtest.so-tmp
/opt/ghc/bin/ghc --make -no-link -fbuilding-cabal-package -O -j8 -static
-outputdir dist/build/libtest.so/libtest.so-tmp -odir dist/build
/libtest.so/libtest.so-tmp -hidir dist/build/libtest.so/libtest.so-tmp-stubdir
dist/build/libtest.so/libtest.so-tmp -i -idist/build/libtest.so/libtest.so-tmp
-isrc -idist/build/autogen -Idist/build/autogen
-Idist/build/libtest.so/libtest.so-tmp
-optP-include -optPdist/build/autogen/cabal_macros.h -hide-all-packages
-package-db dist/package.conf.inplace -package-id
base-4.7.0.1-1a55ebc8256b39ccbff004d48b3eb834 -XHaskell2010
src/Dummy.hs -no-hs-main -threaded
src/Dummy.hs:1:8:
Could not find module ‘Test’
Use -v to see a list of the files searched for.
Please, can you tell me what the cause of the error is? What am I missing?
You need to add Test to the other-modules field.
I'm having trouble building my Haskell library with GHC 7.8.2 and Cabal 1.20.0.2 on OSX 10.9.3 with both -staticlib and -threaded enabled.
The library I'm building exports several functions using FFI to be called from ObjectiveC in an Xcode project. This works fine with just -staticlib enabled, but now I realize I need to call into my Haskell library from multiple OS-threads simultaneously. But when I add -threaded to ghc-options I get an error when linking:
error: libtool: can't locate file for: -lpthread
error: libtool: file: -lpthread is not an object file (not allowed in a library)
Complete ouput:
$ cabal build
Resolving dependencies...
Configuring dpsync-0.1.0.0...
Building dpsync-0.1.0.0...
Preprocessing library dpsync-0.1.0.0...
[ 1 of 11] Compiling Link ( src/Link.hs, dist/build/Link.o )
...
[11 of 11] Compiling HsCocoa ( src/HsCocoa.hs, dist/build/HsCocoa.o )
Linking liba.a ...
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lpthread
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lpthread is not an object file (not allowed in a library)
The linker command that fails looks like this (... replaces a bunch of -l and -L options):
libtool -static -o liba.a dist/build/HsCocoa.o ... -lCffi -lpthread
Does anyone know what could be wrong?
Entire project on GitHub
Edit:
After discussing this on Haskell Cafe it was suggested that this could be a bug in GHC. I created a ticket here: https://ghc.haskell.org/trac/ghc/ticket/9189