haskell-stack: main module to load is ambiguous - haskell

I have multiple executables with non-conflicting names. Yet stack ghci complains that the main module is ambiguous:
$ find . -type f -exec grep -Hi "apple\|banana" {} \; | grep -v work
./ambig.cabal:executable apple
./ambig.cabal: main-is: Apple.hs
./ambig.cabal: ghc-options: -main-is Apple.apple
./ambig.cabal:executable banana
./ambig.cabal: main-is: Banana.hs
./ambig.cabal: ghc-options: -main-is Banana.banana
./src/Apple.hs:module Apple (apple) where
./src/Apple.hs:apple :: IO ()
./src/Apple.hs:apple = putStrLn "I am apple"
./src/Banana.hs:module Banana (banana) where
./src/Banana.hs:banana :: IO ()
./src/Banana.hs:banana = putStrLn "I am banana"
$ stack ghci
The main module to load is ambiguous. Candidates are: [...]
$ stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e
How can I make stack ghci load all these non-conflicting modules?
The complete cabal file:
$ cat ambig.cabal
name: ambig
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10
executable apple
hs-source-dirs: src
main-is: Apple.hs
ghc-options: -main-is Apple.apple
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
executable banana
hs-source-dirs: src
main-is: Banana.hs
ghc-options: -main-is Banana.banana
default-language: Haskell2010
build-depends: base >= 4.7 && < 5

I had the same problem, if I translate what I did on mine onto your project, you should be able to do either of these to choose the main module:
stack ghci --main-is ambig:exe:apple
or
stack ghci --main-is ambig:exe:banana

Related

Haddock invocation from another directory

I can successfully generate haddock html files from inside the src directory:
$ cd src && haddock --html Person.hs -o ../docs && cd ../
Haddock coverage: # some parts were omitted for brevity
Warning: Package name is not available.
100% ( 2 / 2) in 'Person'
But when I try to do it from outside the src directory it doesn't work:
$ haddock --html src/Person.hs -o docs
Haddock coverage:
src/Person.hs:3:1: error:
Could not find module ‘Address’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Address
| ^^^^^^^^^^^^^^
Probably not relevant, but here is Person.hs:
-- | Persons are awesome
module Person where
import Address
-- | I am a nice person living somewhere
data Person = Person { name :: String, address :: Address } deriving ( Show )

atom won't work with .cabal file

I have been learning haskell using the atom editor on Windows 7. This has worked fine until I created a .cabal file. Now I continuously get red error messages.In fact it is so bad to be unusable as the error messages keep popping up faster than you can delete them. The haskell program is a trivial hello world.
module Main where
main :: IO ()
main = putStrLn "Hello from Haskell!"
The .cabal file is as follows:
-- Initial hello-haskell.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: hello-haskell
version: 0.1.0.0
synopsis: Hello Haskell
description: Hello Haskell
license: BSD3
license-file: LICENSE
author: Tyrone Faulkner
maintainer: p75213#gmail.com
-- copyright:
category: None
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
executable hello-haskell
main-is: Main.hs
ghc-options: -Wall -fwarn-tabs
-- other-modules:
-- other-extensions:
build-depends: base >=4.8 && <4.9
hs-source-dirs: src
default-language: Haskell2010
The error message is as follows:
*[Enter steps to reproduce below:]
1. ...
2. ...
Atom Version: 1.8.0
System: Microsoft Windows 7 Professional
Thrown From: haskell-ghc-mod package, v1.17.2
Stack Trace
Haskell-ghc-mod: ghc-mod interactive command type failed with error ghc-modi crashed
At caps: {"version":[5,5,0,0],"fileMap":true,"quoteArgs":true,"optparse":true,"typeConstraints":false,"browseParents":false,"interactiveCaseSplit":false} URI: C:\Users\Tyrone\MyProjects\hello-haskell\src\Main.hs Args: --,1,1 message: log:
-2.884s: {}
-2.884s: "Trying to run ghc-modi in C:\\Users\\Tyrone\\MyProjects\\hello-haskell"
-2.884s: "Checking for ghc-modi in C:\\Users\\Tyrone\\MyProjects\\hello-haskell"
-2.884s: "Spawning new ghc-modi instance for C:\\Users\\Tyrone\\MyProjects\\hello-haskell with",{"cwd":"C:\\Users\\Tyrone\\MyProjects\\hello-haskell","env":{"ALLUSERSPROFILE":"C:\\ProgramData","APPDATA":"C:\\Users\\Tyrone\\AppData\\Roaming","ATOM_HOME":"C:\\Users\\Tyrone\\.atom","CommonProgramFiles":"C:\\Program Files\\Common Files","COMPUTERNAME":"TYRONE-PC","ComSpec":"C:\\Windows\\system32\\cmd.exe","FP_NO_HOST_CHECK":"NO","GHC":"c:\\users\\tyrone\\appdata\\local\\programs\\stack\\i386-windows\\ghc-7.10.3\\bin","GOOGLE_API_KEY":"AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q","HOMEDRIVE":"C:","HOMEPATH":"\\Users\\Tyrone","LOCALAPPDATA":"C:\\Users\\Tyrone\\AppData\\Local","LOGONSERVER":"\\\\TYRONE-PC","NUMBER_OF_PROCESSORS":"2","OS":"Windows_NT","Path":"C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Skype\\Phone\\;C:\\Program Files\\Support Tools\\;C:\\Program Files\\Git\\cmd;C:\\Users\\Tyrone\\AppData\\Roaming\\local\\bin;c:\\users\\tyrone\\appdata\\local\\atom\\bin;c:\\stack_root;c:\\users\\tyrone\\appdata\\local\\programs\\stack\\i386-windows\\ghc-7.10.3\\bin","PATHEXT":".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC","PROCESSOR_ARCHITECTURE":"x86","PROCESSOR_IDENTIFIER":"x86 Family 6 Model 15 Stepping 6, GenuineIntel","PROCESSOR_LEVEL":"6","PROCESSOR_REVISION":"0f06","ProgramData":"C:\\ProgramData","ProgramFiles":"C:\\Program Files","PSModulePath":"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\","PUBLIC":"C:\\Users\\Public","ROOT_ATOM_DIRECTORY":"c:\\users\\tyrone\\appdata\\local\\atom\\bin","SESSIONNAME":"Console","skype":"C:\\Program Files\\Skype\\Phone\\","STACK_ROOT":"c:\\stack_root","SystemDrive":"C:","SystemRoot":"C:\\Windows","TEMP":"C:\\Users\\Tyrone\\AppData\\Local\\Temp","TMP":"C:\\Users\\Tyrone\\AppData\\Local\\Temp","USERDOMAIN":"Tyrone-PC","USERNAME":"Tyrone","USERPROFILE":"C:\\Users\\Tyrone","windir":"C:\\Windows","windows_tracing_flags":"3","windows_tracing_logfile":"C:\\BVTBin\\Tests\\installpackage\\csilogfile.log","NODE_PATH":"C:\\Users\\Tyrone\\AppData\\Local\\atom\\app-1.8.0\\resources\\app.asar\\exports","NODE_ENV":"production","PATH":"C:\\stack_root\\global-project\\.stack-work\\install\\6840de01\\bin;C:\\stack_root\\snapshots\\48375d44\\bin;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Skype\\Phone\\;C:\\Program Files\\Support Tools\\;C:\\Program Files\\Git\\cmd;C:\\Users\\Tyrone\\AppData\\Roaming\\local\\bin;c:\\users\\tyrone\\appdata\\local\\atom\\bin;c:\\stack_root;c:\\users\\tyrone\\appdata\\local\\programs\\stack\\i386-windows\\ghc-7.10.3\\bin"},"encoding":"utf-8","maxBuffer":null}
-2.884s: "Spawning new ghc-modi instance for C:\\Users\\Tyrone\\MyProjects\\hello-haskell with options = ",{"cwd":"C:\\Users\\Tyrone\\MyProjects\\hello-haskell","env":{"ALLUSERSPROFILE":"C:\\ProgramData","APPDATA":"C:\\Users\\Tyrone\\AppData\\Roaming","ATOM_HOME":"C:\\Users\\Tyrone\\.atom","CommonProgramFiles":"C:\\Program Files\\Common Files","COMPUTERNAME":"TYRONE-PC","ComSpec":"C:\\Windows\\system32\\cmd.exe","FP_NO_HOST_CHECK":"NO","GHC":"c:\\users\\tyrone\\appdata\\local\\programs\\stack\\i386-windows\\ghc-7.10.3\\bin","GOOGLE_API_KEY":"AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q","HOMEDRIVE":"C:","HOMEPATH":"\\Users\\Tyrone","LOCALAPPDATA":"C:\\Users\\Tyrone\\AppData\\Local","LOGONSERVER":"\\\\TYRONE-PC","NUMBER_OF_PROCESSORS":"2","OS":"Windows_NT","Path":"C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Skype\\Phone\\;C:\\Program Files\\Support Tools\\;C:\\Program Files\\Git\\cmd;C:\\Users\\Tyrone\\AppData\\Roaming\\local\\bin;c:\\users\\tyrone\\appdata\\local\\atom\\bin;c:\\stack_root;c:\\users\\tyrone\\appdata\\local\\programs\\stack\\i386-windows\\ghc-7.10.3\\bin","PATHEXT":".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC","PROCESSOR_ARCHITECTURE":"x86","PROCESSOR_IDENTIFIER":"x86 Family 6 Model 15 Stepping 6, GenuineIntel","PROCESSOR_LEVEL":"6","PROCESSOR_REVISION":"0f06","ProgramData":"C:\\ProgramData","ProgramFiles":"C:\\Program Files","PSModulePath":"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\","PUBLIC":"C:\\Users\\Public","ROOT_ATOM_DIRECTORY":"c:\\users\\tyrone\\appdata\\local\\atom\\bin","SESSIONNAME":"Console","skype":"C:\\Program Files\\Skype\\Phone\\","STACK_ROOT":"c:\\stack_root","SystemDrive":"C:","SystemRoot":"C:\\Windows","TEMP":"C:\\Users\\Tyrone\\AppData\\Local\\Temp","TMP":"C:\\Users\\Tyrone\\AppData\\Local\\Temp","USERDOMAIN":"Tyrone-PC","USERNAME":"Tyrone","USERPROFILE":"C:\\Users\\Tyrone","windir":"C:\\Windows","windows_tracing_flags":"3","windows_tracing_logfile":"C:\\BVTBin\\Tests\\installpackage\\csilogfile.log","NODE_PATH":"C:\\Users\\Tyrone\\AppData\\Local\\atom\\app-1.8.0\\resources\\app.asar\\exports","NODE_ENV":"production","PATH":"C:\\stack_root\\global-project\\.stack-work\\install\\6840de01\\bin;C:\\stack_root\\snapshots\\48375d44\\bin;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Skype\\Phone\\;C:\\Program Files\\Support Tools\\;C:\\Program Files\\Git\\cmd;C:\\Users\\Tyrone\\AppData\\Roaming\\local\\bin;c:\\users\\tyrone\\appdata\\local\\atom\\bin;c:\\stack_root;c:\\users\\tyrone\\appdata\\local\\programs\\stack\\i386-windows\\ghc-7.10.3\\bin"},"encoding":"utf-8","maxBuffer":null}
-2.884s: "Started interactive action block in C:\\Users\\Tyrone\\MyProjects\\hello-haskell"
-2.884s: "Running ghc-modi command type","C:\\Users\\Tyrone\\MyProjects\\hello-haskell\\src\\Main.hs","--",1,1
-2.419s: "ghc-modi said: "
-2.419s: "ghc-modi said: on the commandline: Warning:"
-2.419s: "ghc-modi said: -package-conf=C:\\Users\\Tyrone\\AppData\\Roaming\\ghc-mod\\cabal-helper\\Cabal-1.24.0.0-db-7.10.3 is deprecated: Use -package-db instead"
-1.936s: "ghc-modi said: [1 of 5] Compiling CabalHelper.Types ( CabalHelper\\Types.hs, C:\\Users\\Tyrone\\AppData\\Roaming\\ghc-mod\\cabal-helper\\CabalHelper\\Types.o )"
-0.807s: "ghc-modi said: [2 of 5] Compiling CabalHelper.Common ( CabalHelper\\Common.hs, C:\\Users\\Tyrone\\AppData\\Roaming\\ghc-mod\\cabal-helper\\CabalHelper\\Common.o )"
-0.445s: "ghc-modi said: [3 of 5] Compiling CabalHelper.Sandbox ( CabalHelper\\Sandbox.hs, C:\\Users\\Tyrone\\AppData\\Roaming\\ghc-mod\\cabal-helper\\CabalHelper\\Sandbox.o )"
-0.228s: "ghc-modi said: [4 of 5] Compiling CabalHelper.Licenses ( CabalHelper\\Licenses.hs, C:\\Users\\Tyrone\\AppData\\Roaming\\ghc-mod\\cabal-helper\\CabalHelper\\Licenses.o )"
-0.071s: "ghc-modi said: "
-0.071s: "ghc-modi said: CabalHelper\\Licenses.hs:38:28:"
-0.071s: "ghc-modi said: Not in scope: `lookupComponentId'"
-0.07s: "ghc-modi said: Perhaps you meant one of these:"
-0.07s: "ghc-modi said: `lookupComponent' (imported from Distribution.Simple.LocalBuildInfo),"
-0.07s: "ghc-modi said: `localComponentId' (imported from Distribution.Simple.LocalBuildInfo)"
-0.07s: "ghc-modi said: "
-0.07s: "ghc-modi said: CabalHelper\\Licenses.hs:53:18:"
-0.07s: "ghc-modi said: Ambiguous occurrence `lookupInstalledPackageId'"
-0.07s: "ghc-modi said: It could refer to either `CabalHelper.Licenses.lookupInstalledPackageId',"
-0.07s: "ghc-modi said: defined at CabalHelper\\Licenses.hs:38:1"
-0.07s: "ghc-modi said: or `Distribution.Simple.PackageIndex.lookupInstalledPackageId',"
-0.07s: "ghc-modi said: imported from `Distribution.Simple.PackageIndex' at CabalHelper\\Licenses.hs:24:1-39"
-0.07s: "ghc-modi said: "
-0.07s: "ghc-modi said: CabalHelper\\Licenses.hs:74:10:"
-0.07s: "ghc-modi said: Ambiguous occurrence `lookupInstalledPackageId'"
-0.07s: "ghc-modi said: It could refer to either `CabalHelper.Licenses.lookupInstalledPackageId',"
-0.07s: "ghc-modi said: defined at CabalHelper\\Licenses.hs:38:1"
-0.07s: "ghc-modi said: or `Distribution.Simple.PackageIndex.lookupInstalledPackageId',"
-0.07s: "ghc-modi said: imported from `Distribution.Simple.PackageIndex' at CabalHelper\\Licenses.hs:24:1-39"
-0.012s: "ghc-modi said: ghc-mod: readCreateProcess: C:\\stack_root\\snapshots\\48375d44\\libexec\\cabal-helper-wrapper.exe \"--with-ghc=ghc\" \"--with-ghc-pkg=ghc-pkg\" \"--with-cabal=cabal\" \"C:\\\\Users\\\\Tyrone\\\\MyProjects\\\\hello-haskell\" \"C:\\\\Users\\\\Tyrone\\\\MyProjects\\\\hello-haskell\\\\dist\" \"package-db-stack\" \"entrypoints\" \"source-dirs\" \"ghc-options\" \"ghc-src-options\" \"ghc-pkg-options\" \"ghc-merged-pkg-options\" \"ghc-lang-options\" \"licenses\" \"flags\" \"config-flags\" \"non-default-config-flags\" \"compiler-version\" (exit 1): failed"
-0.001s: "ghc-modi for C:\\Users\\Tyrone\\MyProjects\\hello-haskell ended with 1"
-0.001s: "ghc-modi for C:\\Users\\Tyrone\\MyProjects\\hello-haskell ended with 1"
-0.001s: "Running ghc-modi command unmap-file","C:\\Users\\Tyrone\\MyProjects\\hello-haskell\\src\\Main.hs" 0s: {"name":"ghc-modi crashed"}
ghc-modi crashed
at module.exports.Util.mkError (file:///C:/Users/Tyrone/.atom/packages/haskell-ghc-mod/lib/util.coffee:225:15)
at ChildProcess.exitCallback (file:///C:/Users/Tyrone/.atom/packages/haskell-ghc-mod/lib/ghc-mod/interactive-process.coffee:77:20)
at emitTwo (events.js:92:20)
at ChildProcess.emit (events.js:172:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
Commands
-2:22.4.0 core:copy (atom-text-editor.editor.is-focused)
Config
json { "core": {
"automaticallyUpdate": false,
"themes": [
"atom-light-ui",
"atom-light-syntax"
] } }
Installed Packages
```coffee
User autocomplete-haskell, v0.6.6 haskell-ghc-mod, v1.17.2 ide-haskell, v1.8.1 ide-haskell-cabal, v1.6.4 ide-haskell-repl, v0.1.0 language-haskell, v1.9.7
Dev No dev packages ```*
a quick guess, without a computer to confirm this. did run into a similar situation and delete the build folder . this happend when I run yesod devel inside the project, and afterward did open the project folder in atom editor, usin ghc-mod on Windows 10. I'll update this answer when I'm back at a computer and learn how to format responses here on stackoverflow. don't delete the build folder if you want to use it later, I assume there is some configuration in the atom addon or in a configuration file for ghc-mod or maybe wrap the ghc-mod configuration to use spesific version of library.
I upgraded to ghc-mod-5.6.0.0. I also have ghc-mod installed in 3 places. As my PATH points to all 3 I have temporarily renamed those old exe files and only using the latest 5.6.0.0.

Cabal package dependencies are satisfied, but I cannot get cabal test to find them

I'm not very experienced with the cabal workflow, so I suspect that the problem that I am having is a simple one. But, I cannot fond a solution.
I have the following dependencies in my cabal file:
$ grep tasty ume.cabal
build-depends: base >=4.7 && <4.8, HDBC >=2.4 && <2.5, parsec >=3.1 && <3.2,
filepath >=1.4 && <1.5,
HDBC-sqlite3 >=2.3 && <2.4, time >=1.5 && <1.6, sqlite >=0.5 && <0.6,
bytestring >=0.10 && <0.11, unix >=2.7 && <2.8, cryptohash >=0.11 && <0.12, process >=1.2 && <1.3,
transformers >= 0.4 && < 0.5, text, base16-bytestring,
utf8-string, tasty >= 0.11 && < 0.12,tasty-hunit >= 0.9 && < 0.10
Ok, when I try to run the test suit, I get this message:
$ cabal test
Re-configuring with test suites enabled. If this fails, please run configure
manually.
Resolving dependencies...
Configuring umecore-hs-0.0.1.0...
cabal: At least the following dependencies are missing:
tasty ==0.11.*, tasty-hunit ==0.9.*
however, when I try to install the missing packages, I get this message:
$ cabal install tasty tasty-hunit
Resolving dependencies...
All the requested packages are already installed:
tasty-0.11.0.1
tasty-hunit-0.9.2
Use --reinstall if you want to reinstall anyway.
So, the dependencies are met. How come I am not able to use the libraries?
EDIT:
Here is the whole cabal file:
name: umecore-hs
version: 0.0.1.0
synopsis: An infrastructure for querying phonetic data
description: A framwork for takeing transcription files into a database structure, so that phonetically relevant queries may be made on the transcriptions.
homepage: https://github.com/dargosch/umecore-hs/wiki
license: BSD3
license-file: LICENSE
author: Fredrik Karlsson
maintainer: fredrik.k.karlsson#umu.se
-- copyright:
category: Database
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
library
exposed-modules: Phonetic.Database.QueryGenerator, Phonetic.Database.SegmentList, Phonetic.Database.UmeDatabase, Phonetic.Database.UmeQuery, Phonetic.IPA.IPAParser, Phonetic.Database.DataTypes, Phonetic.Database.UmeQueryParser, Phonetic.FileParsers.TextgridParser
ghc-options: -W -fno-warn-unused-do-bind -i/Users/frkkan96/Documents/src/umecore-hs/src
-- other-modules:
-- other-extensions:
build-depends: base >=4.8 && < 4.9, HDBC >=2.4 && <2.5, parsec >=3.1 && <3.2, filepath >=1.4 && <1.5, HDBC-sqlite3 >=2.3 && <2.4, time >=1.5 && <1.6, sqlite >=0.5 && <0.6, bytestring >=0.10 && <0.11, unix >=2.7 && <2.8, cryptohash >=0.11 && <0.12, process >=1.2 && <1.3, transformers >= 0.4 && < 0.5, text >= 1.2 && <= 1.3, base16-bytestring >= 0.1.1 && < 1.1.2, utf8-string >= 1 && < 1.1, directory >=1.2 && <1.3, regex-base >= 0.9 && < 1.0, regex-pcre >= 0.94 && < 0.95, regex-base >= 0.93 && < 0.94
hs-source-dirs: src
default-language: Haskell2010
Executable textgrid_import
Main-Is: textgrid_import.hs
Hs-Source-Dirs: src
-- Other-Modules: Phonetic.FileParsers.TextgridParser
default-language: Haskell2010
build-depends: base >=4.8 && <4.9, HDBC >=2.4 && <2.5, parsec >=3.1 && <3.2, filepath >=1.4 && <1.5, HDBC-sqlite3 >=2.3 && <2.4, time >=1.5 && <1.6, sqlite >=0.5 && <0.6, bytestring >=0.10 && <0.11, unix >=2.7 && <2.8, cryptohash >=0.11 && <0.12, process >=1.2 && <1.3, filemanip >=0.3 && < 0.4, directory >=1.2 && <1.3, optparse-applicative >= 0.12 && < 0.13
Executable umequery
Main-Is: umequery.hs
Hs-Source-Dirs: src
default-language: Haskell2010
build-depends: base >=4.8 && <4.9, HDBC >=2.4 && <2.5, parsec >=3.1 && <3.2, filepath >=1.4 && <1.5, HDBC-sqlite3 >=2.3 && <2.4, time >=1.5 && <1.6, sqlite >=0.5 && <0.6, bytestring >=0.10 && <0.11, unix >=2.7 && <2.8, cryptohash >=0.11 && <0.12, optparse-applicative >= 0.12 && < 0.13, text >= 1.2 && <= 1.3, base16-bytestring >= 0.1.1 && < 1.1.2, utf8-string >= 1 && < 1.1, transformers >= 0.4 && < 0.5, regex-pcre >= 0.94 && < 0.95, regex-base >= 0.93 && < 0.94
source-repository head
type: git
location: git://github.com/dargosch/umecore-hs.git
test-suite test
default-language:
Haskell2010
type:
exitcode-stdio-1.0
hs-source-dirs:
src, tests
main-is:
tests.hs
build-depends: base >=4.7 && <4.8, HDBC >=2.4 && <2.5, parsec >=3.1 && <3.2, filepath >=1.4 && <1.5, HDBC-sqlite3 >=2.3 && <2.4, time >=1.5 && <1.6, sqlite >=0.5 && <0.6, bytestring >=0.10 && <0.11, unix >=2.7 && <2.8, cryptohash >=0.11 && <0.12, process >=1.2 && <1.3, transformers >= 0.4 && < 0.5, text, base16-bytestring, utf8-string, tasty >= 0.11 && < 0.12,tasty-hunit >= 0.9 && < 0.10
Running cabal install --enable-tests --only-dependencies should install the dependencies of the test suite.

HUnit tests within cabal sandbox

After having some trouble I managed to configure my Cabal project so that it runs a simple stub test True #=? True. It works still if I substitute one value with a constant from tested package. However when I try to create an instance of a custom datatype to be tested, I get a linking error.
For now the project consists of two modules:
module TestedModule where
data MyDataType = MyData String Char Int deriving Show
boolVal = True
________________________________
module TestTestedModule where
import Test.HUnit
import TestedModule
import qualified Distribution.TestSuite as C
import qualified Distribution.TestSuite.HUnit as H
tests :: IO [C.Test]
tests = return $ map (uncurry H.test) testModule
testModule :: [(String, Test)]
testModule = [{- ("Test Show", testShow), -}
("Test True", testTrue)
]
testTrue = TestCase $ boolVal #? "False!"
-- testShow = TestCase $ "blabla" #=? show (MyData "blabla" 'a' 1)
Now when testShow is commented out, everything is fine, but when I uncomment it, I get:
$ cabal test
Building argparse-0.1.0.0...
Preprocessing library argparse-0.1.0.0...
[1 of 1] Compiling TestedModule ( TestedModule.hs, dist/build/TestedModule.o )
In-place registering package-0.1.0.0...
Preprocessing test suite 'test-module' for package-0.1.0.0...
[1 of 2] Compiling TestedModule ( TestedModule.hs, dist/build/TestedModule.o )
[2 of 2] Compiling TestArgparse ( TestTestedModule.hs, dist/build/TestTestedModule.o ) [TestedModule changed]
In-place registering test-module-0.1.0.0...
[1 of 1] Compiling Main ( dist/build/test-moduleStub/test-moduleStub-tmp/test-moduleStub.hs, dist/build/test-moduleStub/test-moduleStub-tmp/Main.o )
Linking dist/build/test-moduleStub/test-moduleStub ...
/home/sven/Haskell/lib/package/dist/build/libtest-package.a(TestTestedModule.o):(.data+0x50): undefined reference to `testzmargparsezm0zi1zi0zi0_TestedModule_MyData_static_info'
collect2: error: ld returned 1 exit status
The error occurs even if testShow is still commented out in testModule list. package.cabal looks like this:
$ cat package.cabal
-- Initial package.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: package
version: 0.1.0.0
synopsis: Some description
-- description:
license: Apache-2.0
license-file: LICENSE
author: Sventimir
maintainer: xxx#yyyy.com
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
library
exposed-modules: TestedModule
-- other-modules:
-- other-extensions:
-- hs-source-dirs:
default-language: Haskell2010
build-depends: base >=4.7 && <4.8,
HUnit >=1.2 && <1.3,
containers >=0.5 && <0.6
Test-Suite test-module
type: detailed-0.9
test-module: TestTestedModule
default-language: Haskell2010
build-depends: base >=4.7 && <4.8,
Cabal >=1.20.0,
HUnit >=1.2 && <1.3,
cabal-test-hunit,
containers >=0.5
Files are all located in:
$ ls -la /home/sven/Haskell/lib/package
drwxr-xr-x 6 sven users 4096 Oct 5 10:57 .
drwxrwxrwx 6 sven users 4096 Sep 28 11:13 ..
drwxr-xr-x 7 sven users 4096 Oct 5 10:47 .cabal-sandbox
drwxr-xr-x 8 sven users 4096 Oct 5 09:27 .git
-rw-r--r-- 1 sven users 57 Oct 4 19:06 .gitignore
-rw-r--r-- 1 sven users 546 Oct 5 10:57 TestedModule.hs
-rw-r--r-- 1 sven users 11358 Oct 4 09:27 LICENSE
-rw-r--r-- 1 sven users 46 Oct 4 09:27 Setup.hs
-rw-r--r-- 1 sven users 650 Oct 5 10:56 TestTestedModule.hs
-rw-r--r-- 1 sven users 1190 Oct 5 09:39 package.cabal
-rw r--r-- 1 sven users 990 Oct 4 18:02 cabal.sandbox.config
drwxr-xr-x 5 sven users 4096 Oct 5 11:03 dist
drwxr-xr-x 2 sven users 4096 Oct 4 09:19 orid

Segmentation fault when running hs_init(0, 0) for ffi

I am trying to call Haskell functions from python.
I have the following make file:
GHC=ghc
GHC_RUNTIME_LINKER_FLAG=-lHSrts-ghc7.4.1
libffi-example.so: Example.o wrapper.o
$(GHC) -o $# -shared -dynamic -fPIC $^ $(GHC_RUNTIME_LINKER_FLAG)
Example_stub.h Example.o: Example.hs
$(GHC) -c -dynamic -fPIC Example.hs
wrapper.o: wrapper.c Example_stub.h
$(GHC) -c -dynamic -fPIC wrapper.c
clean:
rm -f *.hi *.o *_stub.[ch]
clean-all:
rm -f *.hi *.o *_stub.[ch] *.so
# Runs the example Python program
example: libffi-example.so
python program.py
The only thing wrapper.c does it creating wrappers for hs_init by calling hs_init(0,0);. The wrapper is called example_init
I get a segmentation fault when running make example, in example_init (ie when calling hs_init(0,0)).
Can someone tell me why this is and/or how to fix it?
Thanks!
It ought to work:
"Moreover, hs_init() may be called with NULL for both argc and argv, signalling the absence of command line arguments."
It seems to be a bug in ghc-7.2.1 to ghc-7.4.1:
RFib.hs:
{-# LANGUAGE ForeignFunctionInterface #-}
module RFib where
fib :: Int -> Int
fib n
| n >= 0 = go 0 1 n
| even n = -go 0 1 (-n)
| otherwise = go 0 1 (-n)
where
go a _ 0 = a
go a b k = go b (a+b) (k-1)
foreign export ccall "rfib" fib :: Int -> Int
rfib.c:
#include <stdio.h>
#include <HsFFI.h>
int rfib(int);
int main(void) {
hs_init(0,0);
printf("%d\n", rfib(35));
hs_exit();
return 0;
}
Compile and run:
$ rm rfib.o RFib.hi RFib.o a.out
$ ghc-7.0.2 -O2 -Wall -no-hs-main RFib.hs rfib.c && ./a.out
[1 of 1] Compiling RFib ( RFib.hs, RFib.o )
Linking a.out ...
9227465
$ rm rfib.o RFib.hi RFib.o a.out
$ ghc-7.0.4 -O2 -Wall -no-hs-main RFib.hs rfib.c && ./a.out
[1 of 1] Compiling RFib ( RFib.hs, RFib.o )
Linking a.out ...
9227465
$ rm rfib.o RFib.hi RFib.o a.out
$ ghc-7.2.1 -O2 -Wall -no-hs-main RFib.hs rfib.c && ./a.out
[1 of 1] Compiling RFib ( RFib.hs, RFib.o )
Linking a.out ...
Speicherzugriffsfehler
$ rm rfib.o RFib.hi RFib.o a.out
$ ghc-7.2.2 -O2 -Wall -no-hs-main RFib.hs rfib.c && ./a.out
[1 of 1] Compiling RFib ( RFib.hs, RFib.o )
Linking a.out ...
Speicherzugriffsfehler
$ rm rfib.o RFib.hi RFib.o a.out
$ ghc-7.4.1 -O2 -Wall -no-hs-main RFib.hs rfib.c && ./a.out
[1 of 1] Compiling RFib ( RFib.hs, RFib.o )
Linking a.out ...
Speicherzugriffsfehler
$ rm rfib.o RFib.hi RFib.o a.out
$ ghc-7.4.2 -O2 -Wall -no-hs-main RFib.hs rfib.c && ./a.out
[1 of 1] Compiling RFib ( RFib.hs, RFib.o )
Linking a.out ...
9227465
$ rm rfib.o RFib.hi RFib.o a.out
$ ghc -O2 -Wall -no-hs-main RFib.hs rfib.c && ./a.out
[1 of 1] Compiling RFib ( RFib.hs, RFib.o )
Linking a.out ...
9227465
Changing two lines in rfib.c:
int main(int argc, char *argv[]) {
hs_init(&argc,&argv);
it works with all versions (>= 7.0 that I have installed).
So to fix it
pass &argc and &argv
upgrade GHC
are the two most obvious ways.

Resources