I am trying to add a detailed-0.9 test suite to a cabal package that provides an executable. Thus I added:
test-suite igor2-test
type: detailed-0.9
hs-source-dirs: src
test-module: Igor2.Tests
build-depends: Cabal
There is no library in this package, but the executable uses the same source tree. During cabal test it fails linking:
Preprocessing test suite 'igor2-test' for igor2-0.7.1.3...
[1 of 5] Compiling Syntax.Name ( src/Syntax/Name.hs, dist/build/Syntax/Name.o )
... (more compiling)
[1 of 5] Compiling Syntax.Name ( src/Syntax/Name.hs, dist/build/Syntax/Name.p_o )
... (more compiling)
In-place registering igor2-test-0.7.1.3...
[1 of 1] Compiling Main ( dist/build/igor2-testStub/igor2-testStub-tmp/igor2-testStub.hs, dist/build/igor2-testStub/igor2-testStub-tmp/Main.o )
Linking dist/build/igor2-testStub/igor2-testStub ...
/full/path/to/igor2/dist/build/libigor2-test.a(Tests.o): In function `cd3z_info':
(.text+0x2d7): undefined reference to `igor2zmtestzm0zi7zi1zi3_SyntaxziName_arrowName3_closure'
... (more undefined references)
collect2: error: ld returned 1 exit status
Why is this failing? The function arrowName is defined in the module Syntax.Name and this module is compiled. It is not used in the test module though.
I also tried turning the package into a library and having the test-suite build-depends on the library. The linker error proceeds.
This is the Haskell Platform from OpenSuSE 13.1, GHC 7.8.3 which locks Cabal to 1.18.1.3.
Today I stumbled on the same issue.
I found the following workaround:
Add
other-modules: Syntax.Name
to your test-suite declaration.
Related
I set up a simple cabal project to try and acquaint myself with it better, and I have a very simple Main.hs file:
main :: IO ()
main = putStrLn "Hello, World!"
So then I try to build it, using cabal new-configure and then cabal new-build. There's no problems for the configure command, but building it gives this:
[1 of 1] Compiling Main ( Main.hs, /home/redacted/Documents/Haskell/nixtut/dist-newstyle/build/x86_64-linux/ghc-8.0.1/newp-0.1.0.0/x/newp/build/newp/newp-tmp/Main.o )
Linking /home/daniel/Documents/Haskell/nixtut/dist-newstyle/build/x86_64-linux/ghc-8.0.1/newp-0.1.0.0/x/newp/build/newp/newp ...
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `_IO_enable_locks#GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__mmap#GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__munmap#GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__mprotect#GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__tunable_get_val#GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__sigtimedwait#GLIBC_PRIVATE'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
Here is my .cabal file:
name: newp
version: 0.1.0.0
synopsis: toying around
-- description:
homepage: none
-- bug-reports:
license: BSD-3-Clause
license-file: LICENSE
author: redacted
maintainer: none
-- copyright:
category: practice
extra-source-files: CHANGELOG.md
executable newp
main-is: Main.hs
--other-modules:
-- other-extensions:
build-depends: base ^>=4.9.0.0
-- hs-source-dirs:
default-language: Haskell2010
I can't seem to understand what's wrong. GCC is installed, I'm not trying to link any external library, I'm not using any other modules, I have no idea know what these references allude to.
Any help is appreciated, because frankly, I don't know where to begin with this. I've tried looking online, but all the situations are different and the solutions don't seem to apply to me. I noticed that for others a similar error occurs when there's an issue with linking or not including modules in the cabal file, but I'm not sure how or if that applies here.
While I don't have a definitive answer as to why the error occurred, after reinstalling nix I could finally build the project. So the issue was not with cabal.
I'm currently not using stack at all on this project (just Cabal), and all was going well when everything was in Main.hs. I decided to split up code, moving my dhall dep and related code from my executable deps to my library deps, and now seem to have this strange error when running cabal new-build:
Building executable 'FarmDataServer.exe' for FarmDataServer-0.1.0.0..
<no location info>: warning: [-Wmissing-home-modules]
These modules are needed for compilation but not listed in your .cabal file's other-modules: FDS
FDS.Config.Core
FDS.Config.DhallConf
[2 of 4] Compiling FDS.Config.DhallConf ( src/FDS/Config/DhallConf.hs, /home/brandon/workspace/CIDA/FarmDataServer/dist-newstyle/buil
d/x86_64-linux/ghc-8.4.4/FarmDataServer-0.1.0.0/x/FarmDataServer.exe/build/FarmDataServer.exe/FarmDataServer.exe-tmp/FDS/Config/Dhall
Conf.o )
src/FDS/Config/DhallConf.hs:7:1: error:
Could not find module `Dhall'
Use -v to see a list of the files searched for.
|
7 | import Dhall
| ^^^^^^^^^^^^^^^^^^^^^^
Certainly I'm also a bit confused by the Wmissing-home-modules message since I seem to have added those in my cabal file.
Relevant bits of my .cabal file:
cabal-version: 2.4
name: FarmDataServer
version: 0.1.0.0
library
exposed-modules:
FDS
other-modules:
FDS.Config.Core
, FDS.Config.DhallConf
build-depends: base ^>=4.11.1.0
, conduit ^>=1.3.1
, csv-conduit ^>=0.7.0.0
, dhall ^>=1.20.0
, text ^>=1.2.3.1
hs-source-dirs: src
executable FarmDataServer.exe
main-is: Main.hs
build-depends: base ^>=4.11.1.0
, conduit ^>=1.3.1
, csv-conduit ^>=0.7.0.0
, scotty ^>=0.11.3
, text ^>=1.2.3.1
, FarmDataServer ^>=0.1.0.0
My src folder:
$ pwd
/home/brandon/workspace/CIDA/FarmDataServer/src
$ du -a
4 ./FDS/Config/DhallConf.hs
4 ./FDS/Config/Core.hs
12 ./FDS/Config
16 ./FDS
4 ./FDS.hs
4 ./Main.hs
28 .
For the missing modules, sink your program executable into a directory such that the module hierarchy for yoru library isn't visible:
mkdir program ; mv src/Main.hs program/
and in cabal for the executable
hs-source-dirs: program
For your missing module Dhall, add the dhall build dependency to your executable stanza in the cabal file.
How can Haskell be compiled to Javascript using GHCJS and Haskell Stack?
I have the current version of Haksell Stack 1.5.1.
I can initialize a GHCJS project with this command: stack new ghcjsSetup ghcjs
Once in the project directory I try following the Stack documentation for GHCJS.
I create a stack.yaml file and edit it to match the example from the documentation so that is looks like this.
resolver: lts-7.19
compiler: ghcjs-0.2.1.9007019_ghc-8.0.1
compiler-check: match-exact
setup-info:
ghcjs:
source:
ghcjs-0.2.1.9007019_ghc-8.0.1:
url: http://ghcjs.tolysz.org/ghc-8.0-2017-02-05-lts-7.19-9007019.tar.gz
sha1: d2cfc25f9cda32a25a87d9af68891b2186ee52f9
Following the documentation further I try to install and boot GHCJS with this command:
stack setup
This command produces an output which ends with an error.
Preparing to install GHCJS to an isolated location.
This will not interfere with any system-level installation.
Preparing to download ghcjs-0.2.1.9007019_ghc-8.0.1 ...
Already downloaded.
Unpacking GHCJS into /home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/ ...
Setting up GHCJS build environment
Installing GHCJS (this will take a long time) ...
ghcjs-0.2.1.9007019: configure (lib + exe)
Package ghcjs uses a custom Cabal build, but does not use a custom-setup stanza
Using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
[1 of 2] Compiling Main ( /home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/Setup.hs, /home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/Main.o )
[2 of 2] Compiling StackSetupShim ( /home/u/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/StackSetupShim.o )
Linking /home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/setup ...
Configuring ghcjs-0.2.1.9007019...
ghcjs-0.2.1.9007019: build (lib + exe)
Preprocessing library ghcjs-0.2.1.9007019...
/home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/src/Compiler/JMacro/Base.hs:1:55: warning:
-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS
/home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/src/Compiler/JMacro/QQ.hs:1:55: warning:
-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS
[ 1 of 50] Compiling GHCJS.Prim.TH.Serialized ( lib/ghcjs-prim/GHCJS/Prim/TH/Serialized.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/GHCJS/Prim/TH/Serialized.o )
Because it is too long to post here I have excluded the middle of the output. Which includes lots of warning messages.
[49 of 50] Compiling Compiler.Program ( src/Compiler/Program.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/Compiler/Program.o )
[50 of 50] Compiling GHCJS ( src/GHCJS.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/GHCJS.o )
Preprocessing executable 'ghcjs' for ghcjs-0.2.1.9007019...
[1 of 1] Compiling Main ( src-bin/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/ghcjs/ghcjs-tmp/Main.o )
Linking .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/ghcjs/ghcjs ...
Preprocessing executable 'ghcjs-boot' for ghcjs-0.2.1.9007019...
[1 of 1] Compiling Main ( src-bin/Boot.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/ghcjs-boot/ghcjs-boot-tmp/Main.o )
/home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/src-bin/Boot.hs:690:1: warning: [-Wtabs]
Tab character found here, and in three further locations.
Please use spaces instead.
Linking .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/ghcjs-boot/ghcjs-boot ...
Preprocessing executable 'ghcjs-pkg' for ghcjs-0.2.1.9007019...
[1 of 1] Compiling Main ( src-bin/Pkg.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/ghcjs-pkg/ghcjs-pkg-tmp/Main.o )
Linking .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/ghcjs-pkg/ghcjs-pkg ...
/usr/bin/ld: cannot find -ltinfo
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
-- While building package ghcjs-0.2.1.9007019 using:
/home/u/.stack/programs/x86_64-linux/ghcjs-0.2.1.9007019_ghc-8.0.1/src/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/setup/setup --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.0.0 build lib:ghcjs exe:ghcjs exe:ghcjs-boot exe:ghcjs-pkg exe:ghcjs-run exe:haddock-ghcjs exe:hsc2hs-ghcjs --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
"Linking .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/ghcjs-pkg/ghcjs-pkg ...
/usr/bin/ld: cannot find -ltinfo"
You are missing the libtinfo library which is part of ncurses. Depending on your environment try something like:
sudo apt-get install libtinfo-dev
As an aside, getting all the pieces that ghcjs needs to build successfully is tricky and not well documented as of September 2018. One might hope that as the project matures it will get easier to install, and that a binary package will be produced. Know that you are not the only person who has these issues. It takes some patience and trial-and-error to get ghcjs working right now.
Others have had success using nix, I did not.
I use Haskell Stack in Windows 10
When I try to install gtk as dependency of my own package, I got following messages.
glib-0.13.2.2: configure
glib-0.13.2.2: build
Progress: 1/5
-- While building package glib-0.13.2.2 using:
C:\Users\junyoung\AppData\Local\Temp\stack6012\glib-0.13.2.2\.stack-work\dist\2672c1f3\setup\setup --builddir=.stack-work\dist\2672c1f3 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: C:\Users\junyoung\Documents\HaskellProject\StackProject\Hotepad\.stack-work\logs\glib-0.13.2.2.log
[1 of 2] Compiling SetupWrapper ( SetupWrapper.hs, C:\Users\junyoung\AppData\Local\Temp\stack6012\glib-0.13.2.2\.stack-work\dist\2672c1f3\setup\SetupWrapper.o )
[2 of 2] Compiling Main ( C:\Users\junyoung\AppData\Local\Temp\stack6012\glib-0.13.2.2\Setup.hs, C:\Users\junyoung\AppData\Local\Temp\stack6012\glib-0.13.2.2\.stack-work\dist\2672c1f3\setup\Main.o )
Linking C:\Users\junyoung\AppData\Local\Temp\stack6012\glib-0.13.2.2\.stack-work\dist\2672c1f3\setup\setup.exe ...
[1 of 2] Compiling Gtk2HsSetup ( Gtk2HsSetup.hs, dist\setup-wrapper\Gtk2HsSetup.o )
[2 of 2] Compiling Main ( SetupMain.hs, dist\setup-wrapper\Main.o )
Linking dist/setup-wrapper\setup.exe ...
Configuring glib-0.13.2.2...
Building glib-0.13.2.2...
Preprocessing library glib-0.13.2.2...
.stack-work\dist\2672c1f3\build\System\Glib\StoreValue_hsc_utils.o:StoreValue_hsc_utils.c:(.text+0x0): multiple definition of `__debugbreak'
.stack-work\dist\2672c1f3\build\System\Glib\StoreValue_hsc_make.o:StoreValue_hsc_make.c:(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
linking .stack-work\dist\2672c1f3\build\System\Glib\StoreValue_hsc_make.o failed (exit code 1)
command was: C:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\mingw\bin\gcc.exe .stack-work\dist\2672c1f3\build\System\Glib\StoreValue_hsc_make.o .stack-work\dist\2672c1f3\build\System\Glib\StoreValue_hsc_utils.o -o .stack-work\dist\2672c1f3\build\System\Glib\StoreValue_hsc_make.exe -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib -LC:/msys64/mingw64/lib -lgobject-2.0 -lglib-2.0 -lintl -LC:\Users\junyoung\AppData\Roaming\stack\snapshots\f21484d8\lib\x86_64-windows-ghc-7.10.3\utf8-string-1.0.1.1-L8eKHa7Iv9q7FVKUYW6u4b -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib -LC:\Users\junyoung\AppData\Roaming\stack\snapshots\64a043b0\lib\x86_64-windows-ghc-7.10.3\text-1.2.2.1-HmqVQnZSpjaC156ABqPhne -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\binar_3uXFWMoAGBg0xKP9MHKRwi -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\conta_2C3ZI8RgPO2LBMidXKTvIU -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\bytes_6VWy06pWzJq9evDvK2d4w6 -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\deeps_6vMKxt5sPFR0XsbRWvvq59 -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\array_67iodizgJQIIxYVTp4emlA -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\base_HQfYBxpPvuw8OunzQu6JGM -lwsock32 -luser32 -lshell32 -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\integ_2aU3IZNMF9a7mQ0OzsZ0dS -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib\ghcpr_8TmvWUcS1U1IKHT0levwg3 -LC:\Users\junyoung\AppData\Local\Programs\stack\x86_64-windows\ghc-7.10.3\lib/rts -lm -lwsock32 -lgdi32 -lwinmm
I found that this messages is because of glib.cabal files bug at glib-0.13.2.2, so when I try to install glib separately, I edit glib.cabal (remove -D___attribute__(A)= option on cpp) and install clearly.
However, when I try to install it using stack, stack install gtk command always takes Hackage one instead of installed glib package.
For short, therefore, my question is, how can I using separately installed glib? Or, is there any way to modify packages .cabal file while installing it, using options or whatever?
Stack lets you use a dependency from a local directory, or a github repo. So feel free to fork the project, do the fixes, maybe even do a PR, and then put this into your stack.yaml under "packages" section:
- location:
git: https://github.com/user/repo
commit: a1b3559090e9c75ce1d46969085fe4f918b2fa82
I have some cabal failures after scaffolding my haskell project using the holy-project.
I don't think the issue is related to that plugin (seems more like general cabal question) because I could reproduce it starting from a standard cabal init. I'd be surprised if the issue is related to SublimeHaskell either as many people seem to be using it.
Here is the cabal file that was generated (I simplified/shortened it a bit):
(the holy-project generates some example source files along)
name: test-holy
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10
library
exposed-modules: TestHoly
, TestHoly.Swallow
, TestHoly.Coconut
build-depends: base >=4.7 && <4.8
ghc-options: -Wall
hs-source-dirs: src
default-language: Haskell2010
cabal build works
The following command does not work:
$ cabal clean && cabal configure && cabal build --ghc-options="-fforce-recomp -Wall -fno-code"
cleaning...
Resolving dependencies...
Configuring test-non-holy2-0.1.0.0...
Building test-non-holy2-0.1.0.0...
Preprocessing library test-non-holy2-0.1.0.0...
[1 of 3] Compiling TestHoly.Coconut ( src/TestHoly/Coconut.hs, nothing )
[2 of 3] Compiling TestHoly.Swallow ( src/TestHoly/Swallow.hs, nothing )
[3 of 3] Compiling TestHoly ( src/TestHoly.hs, nothing )
[1 of 3] Compiling TestHoly.Coconut ( src/TestHoly/Coconut.hs, nothing )
[2 of 3] Compiling TestHoly.Swallow ( src/TestHoly/Swallow.hs, nothing )
[3 of 3] Compiling TestHoly ( src/TestHoly.hs, nothing )
ar: dist/build/TestHoly.o: No such file or directory
ar: dist/build/TestHoly/Swallow.o: No such file or directory
ar: dist/build/TestHoly/Coconut.o: No such file or directory
From what I understand, due to the -fno-code flag (Omit code generation) no object files are generated hence the linker fails. Is that expected? Or should the linker not have been called?
Why am I running that cabal command?
As I said earlier on: I'm using SublimeText to edit my project. It fails on the project-holy generated cabal file with the following message:
Build FAILED
REMAINING STDERR:
Warning: the following files would be used as linker inputs, but linking is not being done: dist/build/TestHoly.dyn_o dist/build/TestHoly/Swallow.dyn_o dist/build/TestHoly/Coconut.dyn_o
ghc: no input files
Usage: For basic information, try the `--help' option.
Through the discussion on SublimeHaskell#158 I followed the suggestion by nh2 to run this cabal command directly (because it's the one used by SublimeHaskell).
I'd appreciate if someone can shed a light on this!
Version info
$ cabal --version
cabal-install version 1.18.0.5
using version 1.18.1.4 of the Cabal library
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.3
$ system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: OS X 10.10 (14A389)
Kernel Version: Darwin 14.0.0
This is a known issue in cabal.
See https://github.com/haskell/cabal/issues/1176
If you don't pass -fforce-recomp you might be ok for incremental checking and only hit the error when you needed to do a clean build.
But absent that, cabal just doesn't know what to do when ghc doesn't actually compile things...