Removing dependency on Terminfo package from a GHC compiled binary - haskell

I'd like to remove terminfo package from the default dependencies of my GHC installation, as the generated executable does not run in a particular environment without libtinfo, saying:
./Main: error while loading shared libraries: libtinfo.so.6: cannot
open shared object file: No such file or directory
So, is there any neat way to remove dependency on terminfo package?
The only way I found is to use -hide-all-packages of ghc and then enumerate all required default packages via -package option:
ghc -hide-all-packages -package-db ~/.cabal/store/ghc-8.10.7/package.db \
-package base -package containers -package array -package template-haskell \
-package unix -package filepath -package process -package directory \
-package time --make Main.hs
Options like -hide-package or -ignore-package doesn't work.
$ ghc -ignore-package terminfo -ignore-package ghc --make Main.hs
Loaded package environment from /home/keigoi/.ghc/x86_64-linux-8.10.7/environments/default
<command line>: cannot satisfy -package-id ghc-8.10.7:
ghc-8.10.7 is ignored due to an -ignore-package flag
(use -v for more information)
Any ideas?
Some thoughts and additional findings:
(*) I have no idea why the generated binary depends on it -- the package is required by GHC API, which is not always necessary I think and I didn't use it.
Actually, binaries generated from the fresh installation (as of GHC 8.10 or 9.2 from ghcup) does not depend on libtinfo.
Under the circumstance that ~/.ghc/x86_64-linux-8.10.7/environments/default does not exist, the generated binary has no dependency to libtinfo. This file is generated when you initialize Cabal. After that, the compiled binary will depend on libtinfo.so.
(**) Commands like strip seems not to elimite that dependency.

Related

Cabal / Stack ignores ghc-options for custom Setup scripts

I'm trying to get Stack working on an Arch system. I've done the usual:
pacman -S ghc stack cabal-install
And then placed the following in ~/.stack/config.yaml, so that the system GHC is used and dynamic libraries are used (the packages above do not include static libraries):
system-ghc: true
ghc-options:
"$everything": -dynamic
configure-options:
"$everything":
- -dynamic
But when I try to install something, (i.e. stack install wai) I see that it attempts to build a custom Setup script:
/usr/bin/ghc-8.6.5 -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-2.4.0.1 /home/alba/.stack/setup-exe-src/setup-mPHDZzAJ.hs /home/alba/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /home/alba/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5
And my options are not honored, so the build tries to use static libraries (and fails). Is there any way to get Stack/Cabal to use certain options when building Setup.hs?
EDIT: I found the relevant issues; it doesn't seem to be possible:
stack: Can't use system GHC without static libraries at all (#3409)
cabal: executable-dynamic: True should apply to build-type: Custom setup #1720
Related: It seems cabal will always attempt to build static + dynamic in some cases, even if you tell it otherwise.
For now, a partial solution I ended up using is to force the option with a wrapper.
At ~/.local/bin/ghc-8.6.5 put:
#!/bin/sh
exec /usr/bin/ghc-8.6.5 -dynamic "$#"
Then:
cd ~/.local/bin
chmod +x ghc-8.6.5
ln -s ghc{-8.6.5,}
ln -s {/usr/bin,.}/ghc-pkg-8.6.5
ln -s {/usr/bin,.}/runghc-8.6.5
ln -s {/usr/bin,.}/haddock-ghc-8.6.5
Make sure it's in your PATH and you're good to go.

haskell makefile import library

So I have the following makefile which I want to use to compile my haskell program. However, in my program.hs file I have imported a library that is not in the standard Haskell distribution (e.g. Data.List). As a result, when I try to compile I get the error below. How can I include the said library so that it compiles fine? P.S. I am NOT interested in other approaches which do not involve a makefile, thank you.
error:
Linking program...
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
makefile:
program: program.hs
ghc --make -static -optl-static program.hs
You went down the wrong path with static options. I assume you're on os-x. As explained at ld: library not found for -lcrt0.o on OSX 10.6 with gcc/clang -static flag that just makes things worse. In fact you got a different error, because you got an earlier error.
To write a good makefile, first ensure you can run ghc to compile the program without make, just by running the commands in the shell.
I.e. try to compile just ghc --make program.hs and see what happens. If you have the other libraries in your package environment already, it doesn't matter if they're in the standard distribution or not.

"requested module differs from name found in the interface file"

What I want is: cabal to build my modules; make to build this one script.
The script links to Objective-C (see https://github.com/mchakravarty/language-c-inline/tree/master/tests/objc/marshal-array). when I build the script, it fails on the import:
$ make
Main.hs:1:1:
Bad interface file: dist/build/Commands/OSX/Events.hi
Something is amiss; requested module main:Commands.OSX.Events differs from name found in the interface file commands-0.0.0:Commands.OSX.Events
here are some file contents:
$ cat Makefile
PACKAGES = -package template-haskell -package language-c-quote -package language-c-inline -package commands
FRAMEWORKS = -framework Carbon -framework Cocoa -framework Foundation
LDFLAGS = $(PACKAGES) $(FRAMEWORKS)
Main: Main.o
cabal exec -- ghc -o Main Main.o $(LDFLAGS)
Main.o:
cabal build
cabal exec -- ghc -c Main.hs -idist/build/ -v
...
$ cat commands.cabal
exposed-modules: Commands.OSX.Events
hs-source-dirs: sources
...
$ ghc --show-iface dist/build/Commands/OSX/Events.hi
interface commands-0.0.0:Commands.OSX.Events 7083
...
$ cat sources/Commands/OSX/Events.hs
module Commands.OSX.Events where
...
$ cat Main.hs
import Commands.OSX.Events
...
the cabal build is successful, and executable compiles and runs successfully, if I just put everything in the same directory, and ignore cabal.
can I tell GHC that some module is part of some package?
can I make a cabal executable, with these external dependencies?
any other solutions?
explicitly naming the modules package worked:
ghc -package-name commands-0.0.0
http://www.haskell.org/ghc/docs/7.2.1/html/users_guide/packages.html

Haskell - can't find package

I have a package installed via cabal: Data.Vector
But when I attempt to compile a program that has import Data.Vector in it:
Drews-MacBook-Pro:Blokus-AI drewgross$ ghc --make -O2 -prof -auto-all playGame
Grid.hs:28:8:
Could not find module `Data.Vector'
Perhaps you meant
Data.Tensor (from Tensor-1.0.0.1)
Data.Functor (from base)
Use -v to see a list of the files searched for.
Drews-MacBook-Pro:Blokus-AI drewgross$
The command I used to install was:
cabal install -p --reinstall --force-reinstalls vector
I've done other various thing in my attempt to get my program to compile, but nothing has worked. I'd really like to just delete everything, go back to square one and download the package again. How can I do that?
Edit: further investigation shows that there might be 2 versions of Data.Vector: 0.10.0.1 and 0.9.1, maybe they are conflicting somehow?
Edit: ghc-pkg check lists no errors, but gives me a ton of warnings that look like this:
Warning: haddock-interfaces: /Users/drewgross/.cabal/share/doc/haskell-lexer-1.0/html/haskell-lexer.haddock doesn't exist or isn't a file
Edit: GCHi also doesn't find it
λ> import Data.Vector
<no location info>:
Could not find module `Data.Vector'
Perhaps you meant Data.Functor (from base)
λ>
Edit: ghc-pkg list vector:
Drews-MacBook-Pro:Blokus-AI drewgross$ ghc-pkg list vector
/Library/Frameworks/GHC.framework/Versions/7.4.2-x86_64/usr/lib/ghc-7.4.2/package.conf.d
/Users/drewgross/.ghc/x86_64-darwin-7.4.2/package.conf.d
vector-0.10.0.1
Drews-MacBook-Pro:Blokus-AI drewgross$
and building with -v flag:
Drews-MacBook-Pro:Blokus-AI drewgross$ ghc --make -O2 -prof -auto-all -v playGame
Glasgow Haskell Compiler, Version 7.4.2, stage 2 booted by GHC version 7.4.2
Using binary package database: /usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2/package.conf.d/package.cache
Using binary package database: /Users/drewgross/.ghc/x86_64-darwin-7.4.2/package.conf.d/package.cache
package Cabal-1.16.0.3-e689d8e77b2f476229954cd43b1737bd is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd directory-1.1.0.2-72e928d14fc50f31f7e6404839a15691 unix-2.5.1.1-29636eb78541401e8e00393ef5df097e
package Tensor-1.0.0.1-a8f1a59665c3ebc4867678a14fe1460f is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package binary-0.5.1.1-e62c39c3aba8093e9b9655a4a8d2bce9 is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd bytestring-0.10.0.1-9b03e69060669eabf0b20e150305c7be
package bmp-1.2.3.2-c7572ec2bbb802bfd93fed0953c61d5d is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd binary-0.5.1.1-e62c39c3aba8093e9b9655a4a8d2bce9 bytestring-0.10.0.1-9b03e69060669eabf0b20e150305c7be
package bytestring-0.10.0.1-9b03e69060669eabf0b20e150305c7be is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package ghc-paths-0.1.0.9-4e6c624a3431a4fa7630e4fb77be4c83 is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package haskell-lexer-1.0-8fea1c35b626a2de761522690a88c063 is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package primitive-0.4.1-0007d441db5f4ce1ffd66bd3816c2d4e is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package split-0.2.1.1-03ec5738edb34f2e8967d25637b9392f is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
package vector-0.10.0.1-3450daae3d9f2092020075d05481123c is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd primitive-0.5.0.1-15cdc8c11a54a78809b647af0c2975b3
wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-7d3c2c69a5e8257a04b2c679c40e2fa7
wired-in package integer-gmp mapped to integer-gmp-0.4.0.0-af3a28fdc4138858e0c7c5ecc2a64f43
wired-in package base mapped to base-4.5.1.0-47f48c3ae7f8256a66a23e9dfe22eefc
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.7.0.0-e109822dcbed82c43f9fa60194eb64b5
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: -fscc-profiling -static
*** Chasing dependencies:
Chasing modules from: *playGame.hs
Grid.hs:28:8:
Could not find module `Data.Vector'
Perhaps you meant Data.Functor (from base)
Locations searched:
Data/Vector.hs
Data/Vector.lhs
*** Deleting temp files:
Deleting:
*** Deleting temp dirs:
Deleting:
Drews-MacBook-Pro:Blokus-AI drewgross$
This is what shell uses:
Drews-MacBook-Pro:Blokus-AI drewgross$ which ghc
/usr/bin/ghc
I did cabal install -v lens and obviously there was a ton of output but I think this is the relevant part:
Registering lens-3.7.0.2...
/usr/bin/ghc-pkg update - --global --user
Updating world file...
Drews-MacBook-Pro:Blokus-AI drewgross$
Which seems to indicate that they are using the same version. I can post more of the output of a cabal install if its relevant.
Edit: more ghc output from cabal install -v
Building lens-3.7.0.2...
Preprocessing library lens-3.7.0.2...
Building library...
creating dist/build
/usr/bin/ghc --make -package-name lens-3.7.0.2 -hide-all-packages -fbuilding-cabal-package -i -idist/build -isrc -idist/build/autogen -Idist/build/autogen -Idist/build -optP-DTRUSTWORTHY=1 -optP-DDEFAULT_SIGNATURES=1 -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package-id array-0.4.0.0-0b6c5ca7e879a14d110ca4c001dd9297 -package-id base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd -package-id bytestring-0.9.2.1-0044644a71adfe5e950e6c6f6ca13065 -package-id comonad-3.0.0.2-6ef27fce8536ebdf9c364307a0915f63 -package-id comonad-transformers-3.0-a6df581636b1c9b514cfa6560f17d6a3 -package-id comonads-fd-3.0-b906ed7898871c5d2427052e2eefa62e -package-id containers-0.4.2.1-75f143aa39a3e77a1ce2300025bdd8ce -package-id filepath-1.3.0.0-f998e5510c76a98913f57b14b4f16c57 -package-id ghc-prim-0.2.0.0-7d3c2c69a5e8257a04b2c679c40e2fa7 -package-id hashable-1.1.2.5-14291f3b4e96b5599759ce7daa2bd37c -package-id mtl-2.1.2-02e701f9b1590ee88a0b5b0bd5d93a29 -package-id parallel-3.2.0.3-4cdd6067624f867b253b98d6d9fb9f52 -package-id semigroups-0.8.4.1-4d3a86b037504e6000a0354510588745 -package-id split-0.2.1.1-03ec5738edb34f2e8967d25637b9392f -package-id template-haskell-2.7.0.0-29110cc89a711d6ab3e7ee0e0a8ee949 -package-id text-0.11.2.3-473d9a1761b27c7315f2ef4569d93c3c -package-id transformers-0.3.0.0-8e66ecc7d4dae2b07b2b5406908c70e4 -package-id unordered-containers-0.2.2.1-d70d5ccb1df11dbbbaac89571b1ee46d -package-id vector-0.10.0.1-3450daae3d9f2092020075d05481123c -O -Wall -fwarn-tabs -O2 -fdicts-cheap -funbox-strict-fields -XHaskell98 Control.Lens.TH Language.Haskell.TH.Lens Control.Exception.Lens Control.Lens Control.Lens.Action Control.Lens.Classes Control.Lens.Combinators Control.Lens.Fold Control.Lens.Getter Control.Lens.Indexed Control.Lens.IndexedGetter Control.Lens.IndexedFold Control.Lens.IndexedLens Control.Lens.IndexedSetter Control.Lens.IndexedTraversal Control.Lens.Internal Control.Lens.Internal.Zipper Control.Lens.Iso Control.Lens.Loupe Control.Lens.Plated Control.Lens.Prism Control.Lens.Representable Control.Lens.Setter Control.Lens.Simple Control.Lens.Traversal Control.Lens.Tuple Control.Lens.Type Control.Lens.WithIndex Control.Lens.Wrapped Control.Lens.Zipper Control.Lens.Zoom Data.Bits.Lens Data.ByteString.Lens Data.ByteString.Strict.Lens Data.ByteString.Lazy.Lens Data.Complex.Lens Data.Data.Lens Data.Dynamic.Lens Data.HashSet.Lens Data.IntSet.Lens Data.List.Lens Data.List.Split.Lens Data.Sequence.Lens Data.Set.Lens Data.Text.Lens Data.Text.Strict.Lens Data.Text.Lazy.Lens Data.Tree.Lens Data.Typeable.Lens Data.Vector.Lens Data.Vector.Generic.Lens GHC.Generics.Lens Data.Array.Lens System.FilePath.Lens Control.Parallel.Strategies.Lens Control.Seq.Lens Control.Lens.Internal.Combinators
[ 1 of 57] Compiling Control.Lens.Classes ( src/Control/Lens/Classes.hs, dist/build/Control/Lens/Classes.o )
[ 2 of 57] Compiling Control.Lens.Internal ( src/Control/Lens/Internal.hs, dist/build/Control/Lens/Internal.o )
[ 3 of 57] Compiling Control.Lens.Internal.Combinators ( src/Control/Lens/Internal/Combinators.hs, dist/build/Control/Lens/Internal/Combinators.o )
[ 4 of 57] Compiling Control.Lens.Indexed ( src/Control/Lens/Indexed.hs, dist/build/Control/Lens/Indexed.o )
[ 5 of 57] Compiling Control.Lens.IndexedGetter ( src/Control/Lens/IndexedGetter.hs, dist/build/Control/Lens/IndexedGetter.o )
[ 6 of 57] Compiling Control.Lens.Action ( src/Control/Lens/Action.hs, dist/build/Control/Lens/Action.o )
[ 7 of 57] Compiling Control.Lens.Setter ( src/Control/Lens/Setter.hs, dist/build/Control/Lens/Setter.o )
Edit: ghc-pkg dump
Drews-MacBook-Pro:Blokus-AI drewgross$ ghc-pkg dump | grep "id: base"
id: base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
Your package database is badly broken. The ghc -v output lists ten unusable packages due to missing or recursive dependencies, among them vector:
package vector-0.10.0.1-3450daae3d9f2092020075d05481123c is unusable due to missing or recursive dependencies:
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd primitive-0.5.0.1-15cdc8c11a54a78809b647af0c2975b3
One thing all the broken packages have in common is the missing(?) dependency
base-4.5.1.0-81d626fb996bc7e140a3fd4481b338cd
where the
wired-in package base mapped to base-4.5.1.0-47f48c3ae7f8256a66a23e9dfe22eefc
used base has a different hash.
I'm not sure how this came about, as far as I'm aware, it's impossible to reinstall base, but it looks like you have two exemplars of ghc-7.4.2, and they step on each other's toes.
ghc-pkg list uses
/Library/Frameworks/GHC.framework/Versions/7.4.2-x86_64/usr/lib/ghc-7.4.2/package.conf.d
for the global package database, while the compilation uses
Using binary package database: /usr/local/Cellar/ghc/7.4.2/lib/ghc-7.4.2/package.conf.d/package.cache
Now, it might be that at least one of the two is a symlink and they're both pointing to the same place - then your package.cache is out of sync - but
Glasgow Haskell Compiler, Version 7.4.2, stage 2 booted by GHC version 7.4.2
a GHC booted by the same version seems unusual.
Can you ascertain whether you have indeed two ghc-7.4.2 and the command line uses a different one from the one cabal uses? which ghc tells you which one the shell uses, and cabal install -v some-package outputs the command line cabal uses, including the whole path to the used GHC.
You can list your installed packages with ghc-pkg list. For example (apparently I need to update),
$ ghc-pkg list | grep vector
vector-0.9.1
vector-algorithms-0.5.4
vector-algorithms-0.5.4.2
vector-space-0.8.0
vector-strategies-0.3
You can unregister them using ghc-pkg unregister. Ex,
$ ghc-pkg unregister vector-0.9.1
And then a cabal update && cabal install vector should grab the latest version from hackage.
I had a similar problem with another module after I installed the Haskell Platform over an existing (homebrewed) ghc install [Mac OS Mavericks 10.9.+]. I uninstalled the previous ghc with homebrew
brew uninstall ghc
and re-ran the Haskell Platform installer (.pkg on Mac). I then had to
sudo ghc-pkg recache
to resolve the out-of-date warning upon
ghc-pkg list
This resolved the problem in my case.
You might want to add the package to your .cabal file

Override -Werror when installing from Cabal

I'm trying to install the nano-hmac-0.2.0 package (a dependency of a package I want) from Hackage using Cabal and GHC 6.12.1, but it fails with the following error:
Data/Digest/OpenSSL/HMAC.hsc:1:0:
Warning: Module `Prelude' is deprecated:
You are using the old package `base' version 3.x.
Future GHC versions will not support base version 3.x. You
should update your code to use the new base version 4.x.
<no location info>:
Failing due to -Werror.
Sure enough, the package's .cabal file has the following line in it:
ghc-options: -Wall -Werror -O2 -fvia-C
I'd like to be able to override the -Werror option so I can install the package without manually modifying the .cabal file, but can't find a way that will work. In particular, I tried passing --ghc-options to Cabal to stick a -Wwarn in GHC's argument list, like this:
$ cabal install nano-hmac-0.2.0 -v2 --ghc-options='-Wwarn'
This doesn't do what I want, though; the verbose output verifies that -Wwarn is getting added to the beginning of GHC's argument list, but the -Werror from the .cabal file appears later and seems to override it:
/usr/bin/ghc -Wwarn --make -package-name nano-hmac-0.2.0 -hide-all-packages -fbuilding-cabal-package -i -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package-id base-3.0.3.2-0092f5a086872e0cdaf979254933cd43 -package-id bytestring-0.9.1.5-125aff5b9d19ec30231ae2684b8c8577 -O -Wall -Werror -O2 -fvia-C -XForeignFunctionInterface -XBangPatterns -XCPP Data.Digest.OpenSSL.HMAC
I also tried passing --constraint='base >= 4' to Cabal to force it to use a more recent version of base and avoid the warning entirely, but I get the same failure, and I still see the following in the verbose output:
Dependency base ==3.0.3.2: using base-3.0.3.2
Is there a way to get rid of or override the -Werror coming from the .cabal file via the Cabal command line, or am I stuck modifying the .cabal file myself?
Is there a way to get rid of or override the -Werror coming from the .cabal file via the Cabal command line, or am I stuck modifying the .cabal file myself?
Indeed. There's no way in general. You may be able to override package constraints such that the warnings go away, however, in general, you must modify the .cabal file.
These days Hackage prevents people uploading packages with -Werror in their .cabal file, so the issue will go away over time.

Resources