stack build on macOS - haskell

I am new to haskell. I have the simplest of simple programs.
#!/usr/bin/env stack
-- stack --resolver lts-13.7 script
module Main where
import Lib
main :: IO ()
main = putStrLn "Hello World"
It does work for stack
$stack ./Main.hs
Hello World
(base) 19:48:11/app $
But it suffers a rather gruesome demise on anything more extravagent:
$stack build --test --haddock --no-haddock-hyperlink-source;
Stack has not been tested with GHC versions above 8.6, and using 8.8.3, this may fail
Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail
[1 of 2] Compiling Main ( /Users/steve/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /Users/steve/.stack/setup-exe-src/setup-mPHDZzAJ.o )
[2 of 2] Compiling StackSetupShim ( /Users/steve/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Users/steve/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
Linking /Users/steve/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.3 ...
ld64.lld: warning: ignoring unknown argument: --gc-sections
ld64.lld: warning: ignoring unknown argument: -u
(maybe 50 of these ..)
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -search_paths_first
ld64.lld: warning: ignoring unknown argument: -dead_strip_dylibs
ld64.lld: warning: -sdk_version is required when emitting min version load command. Setting sdk version to match provided min version
Cannot open /Users/steve/.stack/setup-exe-src/setup-mPHDZzAJ.o: bad relocation (Invalid pointer diff) in section __TEXT/__text (r1_address=21c, r1_type=5, r1_extern=1, r1_length=2, r1_pcrel=0, r1_symbolnum=37), (r2_address=21c, r2_type=0, r2_extern=1, r2_length=2, r2_pcrel=0, r2_symbolnum=30)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
-- While building simple Setup.hs using:
/Users/steve/.stack/programs/x86_64-osx/ghc-8.8.3/bin/ghc-8.8.3 -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.0.1.0 /Users/steve/.stack/setup-exe-src/setup-mPHDZzAJ.hs /Users/steve/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /Users/steve/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.3
Process exited with code: ExitFailure 1
I tried searching for these but did not run into obvious matches/solutions. Tips?
Update haskell and stack were installed as such:
brew install haskell-stack
Another update I am trying to navigate to install from the haskell platform.
The asker is not off in left field but instead following the directions provided by the Haskell platform https://www.haskell.org/platform/
There is no download link there so we resort to googling for download ghcup which leads us to https://www.haskell.org/ghcup/
Then running the command
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
The result is:
$curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
This did install ghcup correctly
$ghcup
ghcup 0.0.8
GHC up toolchain installer
USAGE:
ghcup [FLAGS] <SUBCOMMAND>
Next in line: cabal. Google search led me to: https://hackage.haskell.org/package/cabal-install
I downloaded the cabal-install tarball https://hackage.haskell.org/package/cabal-install-3.2.0.0/cabal-install-3.2.0.0.tar.gz
This one was not so cooperative. The short version of the errors is:
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -search_paths_first
ld64.lld: warning: ignoring unknown argument: -dead_strip_dylibs
ld64.lld: warning: -sdk_version is required when emitting min version load command. Setting sdk version to match provided min version
Cannot open ./Distribution/Compat/Async.o: bad relocation (Invalid pointer diff) in section __TEXT/__text (r1_address=2338, r1_type=5, r1_extern=1, r1_length=3, r1_pcrel=0, r1_symbolnum=243), (r2_address=2338, r2_type=0, r2_extern=1, r2_length=3, r2_pcrel=0, r2_symbolnum=237)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
Error during cabal-install bootstrap:
Compiling the Setup script failed.
Full version of errors is:
$./bootstrap.sh
mktemp: illegal option -- p
usage: mktemp [-d] [-q] [-t prefix] [-u] template ...
mktemp [-d] [-q] [-u] -t prefix
Using gcc for C compiler. If this is not what you want, set CC.
Using /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld instead.
Checking installed packages for ghc-8.8.3...
deepseq is already installed and the version is ok.
binary is already installed and the version is ok.
time is already installed and the version is ok.
transformers is already installed and the version is ok.
mtl is already installed and the version is ok.
text is already installed and the version is ok.
parsec is already installed and the version is ok.
network-uri-2.6.1.0 will be downloaded and installed.
network-2.7.0.0 will be downloaded and installed.
HTTP-4000.3.12 will be downloaded and installed.
zlib-0.6.2 will be downloaded and installed.
random-1.1 will be downloaded and installed.
stm is already installed and the version is ok.
hashable-1.2.7.0 will be downloaded and installed.
async-2.2.1 will be downloaded and installed.
base16-bytestring-0.1.1.6 will be downloaded and installed.
base64-bytestring-1.0.0.1 will be downloaded and installed.
cryptohash-sha256-0.11.101.0 will be downloaded and installed.
resolv-0.1.1.1 will be downloaded and installed.
mintty-0.1.2 will be downloaded and installed.
echo-0.1.3 will be downloaded and installed.
edit-distance-0.2.2.1 will be downloaded and installed.
ed25519-0.0.5.0 will be downloaded and installed.
tar-0.5.1.0 will be downloaded and installed.
digest-0.0.1.2 will be downloaded and installed.
lukko-0.1.1 will be downloaded and installed.
hackage-security-0.6.0.0 will be downloaded and installed.
Cabal-3.2.0.0 will be downloaded and installed.
Downloading Cabal-3.2.0.0...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 753k 0 753k 0 0 2879k 0 --:--:-- --:--:-- --:--:-- 2888k
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 27320 0 27320 0 0 188k 0 --:--:-- --:--:-- --:--:-- 189k
[ 1 of 236] Compiling Distribution.Compat.Async ( Distribution/Compat/Async.hs, Distribution/Compat/Async.o )
[ 2 of 236] Compiling Distribution.Compat.Binary ( Distribution/Compat/Binary.hs, Distribution/Compat/Binary.o )
[ 3 of 236] Compiling Distribution.Compat.Directory ( Distribution/Compat/Directory.hs, Distribution/Compat/Directory.o )
[ 4 of 236] Compiling Distribution.Compat.Exception ( Distribution/Compat/Exception.hs, Distribution/Compat/Exception.o )
[ 5 of 236] Compiling Distribution.Compat.FilePath ( Distribution/Compat/FilePath.hs, Distribution/Compat/FilePath.o )
[ 7 of 236] Compiling Distribution.Compat.Internal.TempFile ( Distribution/Compat/Internal/TempFile.hs, Distribution/Compat/Internal/TempFile.o )
( 200 other compiling lines ..)
[230 of 236] Compiling Distribution.Simple.Configure ( Distribution/Simple/Configure.hs, Distribution/Simple/Configure.o )
[231 of 236] Compiling Distribution.Simple.SrcDist ( Distribution/Simple/SrcDist.hs, Distribution/Simple/SrcDist.o )
[232 of 236] Compiling Distribution.Simple.Build ( Distribution/Simple/Build.hs, Distribution/Simple/Build.o )
[233 of 236] Compiling Distribution.Simple.Haddock ( Distribution/Simple/Haddock.hs, Distribution/Simple/Haddock.o )
[234 of 236] Compiling Distribution.Simple.Doctest ( Distribution/Simple/Doctest.hs, Distribution/Simple/Doctest.o )
[235 of 236] Compiling Distribution.Simple ( Distribution/Simple.hs, Distribution/Simple.o )
[236 of 236] Compiling Main ( Setup.hs, Setup.o )
Linking Setup ...
ld64.lld: warning: ignoring unknown argument: --gc-sections
ld64.lld: warning: ignoring unknown argument: -u
(80 other similar lines..)
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -search_paths_first
ld64.lld: warning: ignoring unknown argument: -dead_strip_dylibs
ld64.lld: warning: -sdk_version is required when emitting min version load command. Setting sdk version to match provided min version
Cannot open ./Distribution/Compat/Async.o: bad relocation (Invalid pointer diff) in section __TEXT/__text (r1_address=2338, r1_type=5, r1_extern=1, r1_length=3, r1_pcrel=0, r1_symbolnum=243), (r2_address=2338, r2_type=0, r2_extern=1, r2_length=3, r2_pcrel=0, r2_symbolnum=237)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
Error during cabal-install bootstrap:
Compiling the Setup script failed.
And Another update
Per a comment from #bradm I have tried the Haskell Stack http://docs.haskellstack.org/en/stable/README/#how-to-install . The same errors occur as at beginning of my question. I did double check that the stack were newly installed and it shows right now timestamp. It fails on stack setup within a new dummy project and has the same signature of long ugly errors including linker error on Main.o bad relocation . Here is the core of it (same as at top):
Cannot open /Users/steve/.stack/setup-exe-src/setup-mPHDZzAJ.o: bad relocation (Invalid pointer diff) in section __TEXT/__text (r1_address=21c, r1_type=5, r1_extern=1, r1_length=2, r1_pcrel=0, r1_symbolnum=37), (r2_address=21c, r2_type=0, r2_extern=1, r2_length=2, r2_pcrel=0, r2_symbolnum=30)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
-- While building simple Setup.hs using:
/Users/steve/.stack/programs/x86_64-osx/ghc-8.8.3/bin/ghc-8.8.3
-rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.0.1.0 /Users/steve/.stack/setup-exe-src/setup-mPHDZzAJ.hs /Users/steve/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /Users/steve/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.3
Process exited with code: ExitFailure 1

I just found this known bug: https://github.com/commercialhaskell/stack/issues/4373
That is exactly what I'm seeing.
The workaround required is to update a settings file that is buried deep under a newly generated ~/.stack directory https://github.com/commercialhaskell/stack/issues/4373#issuecomment-432726112
Those instructions are incomplete so I added a comment to that bug to clarify. That settings location: ~/.stack/programs/x86_64-osx/ghc-8.8.3/lib/ghc-8.8.3/settings
And this works (note that stack test is a combination of stack build and stack test):
(base) 10:27:09/haskelltest $stack test
Stack has not been tested with GHC versions above 8.6, and using 8.8.3, this may fail
Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail
Linking /Users/steve/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.3 ...
clang-9: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
clang-9: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
Building all executables for `haskelltest' once. After a successful build of all of them, only specified executables will be rebuilt.
haskelltest> configure (lib + exe + test)
Configuring haskelltest-0.1.0.0...
clang-9: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
haskelltest> build (lib + exe + test)
Preprocessing library for haskelltest-0.1.0.0..
Building library for haskelltest-0.1.0.0..
[1 of 2] Compiling Lib
[2 of 2] Compiling Paths_haskelltest
Preprocessing test suite 'haskelltest-test' for haskelltest-0.1.0.0..
Building test suite 'haskelltest-test' for haskelltest-0.1.0.0..
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_haskelltest
Linking .stack-work/dist/x86_64-osx/Cabal-3.0.1.0/build/haskelltest-test/haskelltest-test ...
clang-9: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
clang-9: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
Preprocessing executable 'haskelltest-exe' for haskelltest-0.1.0.0..
Building executable 'haskelltest-exe' for haskelltest-0.1.0.0..
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_haskelltest
Linking .stack-work/dist/x86_64-osx/Cabal-3.0.1.0/build/haskelltest-exe/haskelltest-exe ...
clang-9: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
clang-9: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
haskelltest> copy/register
Installing library in /git/rubytest/haskelltest/.stack-work/install/x86_64-osx/18cf924ea0be80a27100889c349bd98b50cf064de8de23f912f9f822b43a80db/8.8.3/lib/x86_64-osx-ghc-8.8.3/haskelltest-0.1.0.0-48zsyNIR9r7Efmr0ATZ6Im
Installing executable haskelltest-exe in /git/rubytest/haskelltest/.stack-work/install/x86_64-osx/18cf924ea0be80a27100889c349bd98b50cf064de8de23f912f9f822b43a80db/8.8.3/bin
Registering library for haskelltest-0.1.0.0..
haskelltest> test (suite: haskelltest-test)
Progress 1/2: haskelltestTest suite not yet implemented
haskelltest> Test suite haskelltest-test passed
Completed 2 action(s).

Related

Windows: gcc.exe failed in phase Linker when Stack Run Rio Template

I downloaded and installed stack using the installer on Windows.
I then try to run:
$ stack new new-project rio
$ cd new-project
$ stack run
This leads to this error:
WARNING: Ignoring mintty's bounds on Win32 (>=2.13.1); using Win32-2.6.2.1.
Reason: trusting snapshot over cabal file dependency information.
Linking C:\\sr\\setup-exe-cache\\x86_64-windows\\tmp-Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe ...
C://Users//Patrick//AppData//Local//Programs//stack//x86_64-windows//ghc-8.10.7//mingw//bin/ld.exe: C:\\sr\setup-exe-src\setup-Z6RU0evB.o:fake:(.text+0x232): undefined reference to `Cabalzm3zi0zi1zi0_DistributionziSimple_defaultMain_closure'
C://Users//Patrick//AppData//Local//Programs//stack//x86_64-windows//ghc-8.10.7//mingw//bin/ld.exe: C:\\sr\setup-exe-src\setup-Z6RU0evB.o:fake:(.data+0x178): undefined reference to `Cabalzm3zi0zi1zi0_DistributionziSimple_defaultMain_closure'
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
-- While building simple Setup.hs (scroll up to its section to see the error) using:
C:\Users\Patrick\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.7\bin\ghc-8.10.7.exe -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.2.1.0 C:\sr\setup-exe-src\setup-Z6RU0evB.hs C:\sr\setup-exe-src\setup-shim-Z6RU0evB.hs -o C:\sr\setup-exe-cache\x86_64-windows\tmp-Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe
How can I resolve it? I am not even sure how to better understand the actual problem.
I am working with git bash.
I resolved the WARNING by editing stack.yaml. I have also tried installing pkg-config using pacman on mingw as in this answer but the package was not found.

Why ghc 8.8.4 can't compile a file that ghci can load?

In Mac OS 10.15.7, with haskell platform installed, I am having a weird behavior. The code works fine in ghci but the linking during compilation is not working:
% ghc Merge.hs
Loaded package environment from /Users/ar/.ghc/x86_64-darwin-8.8.4/environments/default
[1 of 1] Compiling Main ( Merge.hs, Merge.o ) [Optimisation flags changed]
Linking Merge ...
ld: can't open output file for writing: Merge, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
But ghci works fine:
% ghci Merge.hs
GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /Users/ar/.ghc/x86_64-darwin-8.8.4/environments/default
[1 of 1] Compiling Main ( Merge.hs, interpreted )
Ok, one module loaded.
*Main>
Also, % stack runghc -- Merge works but
% stack ghc -- Merge
[1 of 1] Compiling Main ( Merge.hs, Merge.o ) [Data.Aeson changed]
Linking Merge ...
ld: can't open output file for writing: Merge, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
Any idea? I have installed the haskell platform following the instructions in https://www.haskell.org/downloads/ with https://www.haskell.org/platform/mac.html (ghcup).
Code is https://gist.github.com/arademaker/e7ae2e1ef5225807a3e627caa61481da
I had a directory with the same name in the folder! My mistake.

Linker can't find Parsec library

I'm trying do some web scraping using HXT, but one dependency, hxt-regex-xmlschema-9.2.0, always fails to install. The error is ld: library not found for -lHSparsec-3.1.7-ghc7.8.3. I don't understand why the linking is failing. I have parsec installed - cabal install parsec-3.1.7 worked fine. I'm running OSX 10.10.1, GHC 7.8.3, and gcc 4.9.1.
EDIT: The output from cabal install hxt-regex-xmlschema-9.2.0:
Configuring hxt-regex-xmlschema-9.2.0...
Dependency base ==4.7.0.1: using base-4.7.0.1
Dependency bytestring ==0.10.4.0: using bytestring-0.10.4.0
Dependency hxt-charproperties ==9.2.0.0: using hxt-charproperties-9.2.0.0
Dependency parsec ==3.1.7: using parsec-3.1.7
Dependency text ==1.2.0.3: using text-1.2.0.3
/usr/local/bin/ghc --info
Using Cabal-1.18.1.4 compiled by ghc-7.8
Using compiler: ghc-7.8.3
Using install prefix: /Users/rjayatilleka/.cabal
Binaries installed in: /Users/rjayatilleka/.cabal/bin
Libraries installed in:
/Users/rjayatilleka/.cabal/lib/x86_64-osx-ghc-7.8.3/hxt-regex-xmlschema-9.2.0
Private binaries installed in: /Users/rjayatilleka/.cabal/libexec
Data files installed in:
/Users/rjayatilleka/.cabal/share/x86_64-osx-ghc-7.8.3/hxt-regex-xmlschema-9.2.0
Documentation installed in:
/Users/rjayatilleka/.cabal/share/doc/x86_64-osx-ghc-7.8.3/hxt-regex-xmlschema-9.2.0
Configuration files installed in: /Users/rjayatilleka/.cabal/etc
Using alex version 3.0.5 found on system at: /usr/local/bin/alex
Using ar found on system at: /usr/bin/ar
Using c2hs version 0.17.2 found on system at:
/Users/rjayatilleka/.cabal/bin/c2hs
Using cpphs version 1.18.5 found on system at:
/Users/rjayatilleka/.cabal/bin/cpphs
No ffihugs found
Using gcc version 4.9.1 found on system at: /usr/local/bin/gcc
Using ghc version 7.8.3 found on system at: /usr/local/bin/ghc
Using ghc-pkg version 7.8.3 found on system at: /usr/local/bin/ghc-pkg
No greencard found
Using haddock version 2.14.3 found on system at: /usr/local/bin/haddock
Using happy version 1.18.10 found on system at: /usr/local/bin/happy
No hmake found
Using hpc version 0.67 found on system at: /usr/local/bin/hpc
Using hsc2hs version 0.67 found on system at: /usr/local/bin/hsc2hs
Using hscolour version 1.20 found on system at:
/Users/rjayatilleka/.cabal/bin/HsColour
No hugs found
No jhc found
Using ld found on system at: /usr/bin/ld
No lhc found
No lhc-pkg found
No nhc98 found
Using pkg-config version 0.28 found on system at: /usr/local/bin/pkg-config
Using ranlib found on system at: /usr/bin/ranlib
Using strip found on system at: /usr/bin/strip
Using tar found on system at: /usr/bin/tar
No uhc found
Component build order: library
creating dist/build
creating dist/build/autogen
Building hxt-regex-xmlschema-9.2.0...
Preprocessing library hxt-regex-xmlschema-9.2.0...
Building library...
/usr/local/bin/ghc --info
/usr/local/bin/ghc --info
creating dist/build
/usr/local/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -package-name hxt-regex-xmlschema-9.2.0 -hide-all-packages -package-db dist/package.conf.inplace -package-id base-4.7.0.1-c64d224738ec7af4085e89ca9c12c37b -package-id bytestring-0.10.4.0-18fe2f3ce284617c82da1702e16772cf -package-id hxt-charproperties-9.2.0.0-36acaa39288f4b2bce2f5dc5cd48c479 -package-id parsec-3.1.7-764aedfe24d8f24850146ae17e380232 -package-id text-1.2.0.3-ebea8c0126422e0e6e5e972676f2f18d -XHaskell2010 Text.Regex.Glob.String Text.Regex.Glob.Generic Text.Regex.Glob.Generic.RegexParser Text.Regex.XMLSchema.String Text.Regex.XMLSchema.Generic Text.Regex.XMLSchema.Generic.Matching Text.Regex.XMLSchema.Generic.RegexParser Text.Regex.XMLSchema.Generic.Regex Text.Regex.XMLSchema.Generic.StringLike -threaded -rtsopts -Wall -fwarn-tabs -funbox-strict-fields
[1 of 9] Compiling Text.Regex.XMLSchema.Generic.StringLike ( src/Text/Regex/XMLSchema/Generic/StringLike.hs, dist/build/Text/Regex/XMLSchema/Generic/StringLike.o )
[2 of 9] Compiling Text.Regex.XMLSchema.Generic.Regex ( src/Text/Regex/XMLSchema/Generic/Regex.hs, dist/build/Text/Regex/XMLSchema/Generic/Regex.o )
[3 of 9] Compiling Text.Regex.XMLSchema.Generic.RegexParser ( src/Text/Regex/XMLSchema/Generic/RegexParser.hs, dist/build/Text/Regex/XMLSchema/Generic/RegexParser.o )
[4 of 9] Compiling Text.Regex.XMLSchema.Generic.Matching ( src/Text/Regex/XMLSchema/Generic/Matching.hs, dist/build/Text/Regex/XMLSchema/Generic/Matching.o )
[5 of 9] Compiling Text.Regex.XMLSchema.Generic ( src/Text/Regex/XMLSchema/Generic.hs, dist/build/Text/Regex/XMLSchema/Generic.o )
[6 of 9] Compiling Text.Regex.XMLSchema.String ( src/Text/Regex/XMLSchema/String.hs, dist/build/Text/Regex/XMLSchema/String.o )
[7 of 9] Compiling Text.Regex.Glob.Generic.RegexParser ( src/Text/Regex/Glob/Generic/RegexParser.hs, dist/build/Text/Regex/Glob/Generic/RegexParser.o )
[8 of 9] Compiling Text.Regex.Glob.Generic ( src/Text/Regex/Glob/Generic.hs, dist/build/Text/Regex/Glob/Generic.o )
[9 of 9] Compiling Text.Regex.Glob.String ( src/Text/Regex/Glob/String.hs, dist/build/Text/Regex/Glob/String.o )
Linking...
/usr/bin/ar -r -s dist/build/libHShxt-regex-xmlschema-9.2.0.a dist/build/Text/Regex/Glob/String.o dist/build/Text/Regex/Glob/Generic.o dist/build/Text/Regex/Glob/Generic/RegexParser.o dist/build/Text/Regex/XMLSchema/String.o dist/build/Text/Regex/XMLSchema/Generic.o dist/build/Text/Regex/XMLSchema/Generic/Matching.o dist/build/Text/Regex/XMLSchema/Generic/RegexParser.o dist/build/Text/Regex/XMLSchema/Generic/Regex.o dist/build/Text/Regex/XMLSchema/Generic/StringLike.o
ar: creating archive dist/build/libHShxt-regex-xmlschema-9.2.0.a
/usr/local/bin/ghc -shared -dynamic -package-name hxt-regex-xmlschema-9.2.0 -no-auto-link-packages -package-db dist/package.conf.inplace -package-id base-4.7.0.1-c64d224738ec7af4085e89ca9c12c37b -package-id bytestring-0.10.4.0-18fe2f3ce284617c82da1702e16772cf -package-id hxt-charproperties-9.2.0.0-36acaa39288f4b2bce2f5dc5cd48c479 -package-id parsec-3.1.7-764aedfe24d8f24850146ae17e380232 -package-id text-1.2.0.3-ebea8c0126422e0e6e5e972676f2f18d dist/build/Text/Regex/Glob/String.dyn_o dist/build/Text/Regex/Glob/Generic.dyn_o dist/build/Text/Regex/Glob/Generic/RegexParser.dyn_o dist/build/Text/Regex/XMLSchema/String.dyn_o dist/build/Text/Regex/XMLSchema/Generic.dyn_o dist/build/Text/Regex/XMLSchema/Generic/Matching.dyn_o dist/build/Text/Regex/XMLSchema/Generic/RegexParser.dyn_o dist/build/Text/Regex/XMLSchema/Generic/Regex.dyn_o dist/build/Text/Regex/XMLSchema/Generic/StringLike.dyn_o -o dist/build/libHShxt-regex-xmlschema-9.2.0-ghc7.8.3.dylib
ld: library not found for -lHSparsec-3.1.7-ghc7.8.3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Reading available packages...
Choosing modular solver.
Resolving dependencies...
Ready to install hxt-regex-xmlschema-9.2.0
Waiting for install task to finish...
Extracting
/Users/rjayatilleka/.cabal/packages/hackage.haskell.org/hxt-regex-xmlschema/9.2.0/hxt-regex-xmlschema-9.2.0.tar.gz
to
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074...
Updating hxt-regex-xmlschema.cabal with the latest revision from the index.
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist/setup
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist/setup
/Users/rjayatilleka/.cabal/setup-exe-cache/setup-Cabal-1.18.1.4-ghc-7.8.3
configure --verbose=2 --ghc --prefix=/Users/rjayatilleka/.cabal --user
--constraint=text ==1.2.0.3 --constraint=parsec ==3.1.7
--constraint=hxt-charproperties ==9.2.0.0 --constraint=bytestring ==0.10.4.0
--constraint=base ==4.7.0.1 --disable-tests --disable-benchmarks
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist/setup
/Users/rjayatilleka/.cabal/setup-exe-cache/setup-Cabal-1.18.1.4-ghc-7.8.3
build --verbose=2
Failed to install hxt-regex-xmlschema-9.2.0
World file is already up to date.
cabal: Error: some packages failed to install:
hxt-regex-xmlschema-9.2.0 failed during the building phase. The exception was:
ExitFailure 1
Well, I kind of left it for a while, and came back to it now. It worked for some reason. The only thing I can think of is that I upgraded from GHC 7.8.3 to 7.8.4. If anyone comes up with this again, try a different version of GHC.

Unable to build Haskell project with options -staticlib and -threaded on OSX

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

Missing symbol in Haskell libclang binding: clang_toggleCrashRecovery

have a bug with libClang, then i install it with cabal at the end i get:
[13 of 13] Compiling Clang ( src/Clang.hs, dist/build/Clang.o )
In file included from ./src/Clang/FFI_stub_ffi.h:6,
from src/Clang/FFI_stub_ffi.c:4:0:
/usr/local/lib/ghc-7.0.3/include/HsFFI.h:29:0:
warning: "__STDC_LIMIT_MACROS" redefined
<command-line>:0:0:
note: this is the location of the previous definition
src/Clang/FFI_stub_ffi.c: In function ‘prim_getCString’:
src/Clang/FFI_stub_ffi.c:33:0:
warning: assignment discards qualifiers from pointer target type
src/Clang/FFI_stub_ffi.c: In function ‘prim_toggleCrashRecovery’:
src/Clang/FFI_stub_ffi.c:2181:0:
warning: implicit declaration of function ‘clang_toggleCrashRecovery’
Registering LibClang-0.0.9...
when i now want to compile a script with ghc that uses Clang i get:
ghc --make test.hs -L.
[1 of 1] Compiling Main ( test.hs, test.o )
Linking test ...
/home/foo/.cabal/lib/LibClang-0.0.9/ghc-7.0.3/libHSLibClang-0.0.9.a(FFI_stub_ffi.o): In function `prim_toggleCrashRecovery':
FFI_stub_ffi.c:(.text+0x1577): undefined reference to `clang_toggleCrashRecovery'
collect2: ld returned 1 exit status
someone a idea what to do?
I can reproduce this on Arch Linux / x86_64: my libclang build emits a warning about the missing symbol,
src/Clang/FFI_stub_ffi.c:2181:1:
warning: implicit declaration of function ‘clang_toggleCrashRecovery’
[-Wimplicit-function-declaration]
Registering LibClang-0.0.9...
Installing library in /home/dons/.cabal/lib/LibClang-0.0.9/ghc-7.0.3
Registering LibClang-0.0.9...
and linking a test program:
import Clang
main = print "yes"
fails with:
$ ghc --make A.hs
Linking A ...
/home/dons/.cabal/lib/LibClang-0.0.9/ghc-7.0.3/libHSLibClang-0.0.9.a(FFI_stub_ffi.o):
In function `prim_toggleCrashRecovery':
FFI_stub_ffi.c:(.text+0x3513): undefined reference to `clang_toggleCrashRecovery'
collect2: ld returned 1 exit status
The process of solving these kind of linker errors is to identify which C library archive that symbol lives in. Searching in my libclang install, I can't find this symbol:
$ find . -type f -exec grep toggleCrashRecovery {} \;
$ grep toggleCrashRecovery /usr/lib/llvm/*
$ grep toggleCrashRecovery /usr/lib/llvm/*/*
zsh: no matches found: /usr/lib/llvm/*/*
which is a clue that it might be something only available in a different version of libclang. I'm using clang/llvm 2.9, which does not have this symbol, while google does turn up some older headers that do include it. So my best guess is that this symbol is no longer available in LLVM, and thus the current haskell/libclang package depends on LLVM/Clang 2.8.
Solution:
Download the libclang source,
$ cabal unpack libclang
and patch it to remove references to the toggle* functions.
$ ghc --make A.hs
[1 of 1] Compiling Main ( A.hs, A.o )
Linking A ...
A patched version is here: http://www.galois.com/~dons/tmp/LibClang-0.0.10.tar.gz
I've also forwarded this info to the author.
Thanks Don for the quick fix.
This issue is fixed with the latest version on Hackage:
http://hackage.haskell.org/package/LibClang-0.1.0
Please "cabal update" and you should be good to go.
Alternatively, you could get the source from https://github.com/chetant/LibClang

Resources