How can I fix the "Unacceptable result type in foreign declaration: CULong" error building gtk2hs packages? - haskell

When trying to compile the gtk Haskell package with ghc-7.6.1, I get the following error (when trying to build pango, one of the dependencies, but it also occurs in other dependency packages if I try to install them manually):
[ 1 of 14] Compiling Graphics.Rendering.Pango.Types ( dist/build/Graphics/Rendering/Pango/Types.hs, dist/build/Graphics/Rendering/Pango/Types.o )
Graphics/Rendering/Pango/Types.chs:249:1:
Unacceptable result type in foreign declaration: CULong
When checking declaration:
foreign import ccall unsafe "static pango_context_get_type" pango_context_get_type
:: CULong
I previously installed an older version of gtk2hs, and so this occurs during an upgrade.
How can I fix the error?

This problem occurs if you have old versions of the gtk2hs-buildtools installed, which don't work with newer versions of ghc. The solution is to update your gtk2hs-buildtools package before continuing with the update:
sudo cabal install --reinstall gtk2hs-buildtools

Related

Haskell cannot import GHC.SrcLoc

I can't get module "GHC.SrcLoc" in package "srcloc" on Ubuntu Haskell ...
-- "import" works on Windows, but not on Ubuntu 14.04
-- Module name is "GHC.SrcLoc"
-- Cabal build error below
Take 2: tried adding package "srcloc" to Cabal dependencies
^ Adding "srcloc" to dependencies causes "cabal configuration failed". ^
GHCI version...
$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3
Please help
https://hackage.haskell.org/package/base-4.8.2.0/docs/GHC-SrcLoc.html
My Haskell Code...
https://github.com/JohnReedLOL/HaskellPrintDebugger
* Attempt #1 *
:~/IdeaProjects/IntelliJHaskellPrintDebugger$ cabal install srcloc
Resolving dependencies...
All the requested packages are already installed:
srcloc-0.5.1.0
Use --reinstall if you want to reinstall anyway.
* Attempt #2 *
-- Tried replacing "import GHC.SrcLoc" with "import Data.Loc", but failed.
-- Tried adding "srcLock" to "build-depends" in .cabal, but failed.
^ Hopeless
Since Data.SrcLoc is a part of the GHC distribution and it wasn't added until (I believe) GHC 7.10.1, it will not exist in GHC 7.6.3. If you install the latest version of GHC, this should work fine.
The package you are seeing that is called srcloc appears to be unrelated to what you want, and does not provide the GHC.SrcLoc module. The GHC.SrcLoc module is instead provided by the GHC base standard library, which is included in (and requires) a newer version of GHC.
Newer versions of GHC also include a lot of other nice features that 7.6.3 (which was released more than 2 years ago) doesn't have.
You also mentioned stack traces, so you might be interested in this.
You must install the srcloc package; in the simple case where you are not using sandboxes, this is done by running cabal install srcloc at the command line.

Cabal fails to install dependencies, but can install them if asked directly

I've seen a very strange recurring problem with Cabal that's interfering with my ability to get repeatable Haskell builds. I have a cabal project with a sandbox. If I do cabal install, I get errors of the form
Y failed during the building phase. The exception was:
ExitFailure 1
X depends on Y which failed to install.
where X is a direct dependency of my project and Y is some transitive dependency. However, if I just type cabal install X, then it works!
Here's a specific example: my project depends on the interpolate package. When I do cabal install --allow-newer, I get errors like this:
Resolving dependencies...
Configuring haskell-src-meta-0.6.0.9...
Building haskell-src-meta-0.6.0.9...
Preprocessing library haskell-src-meta-0.6.0.9...
[1 of 6] Compiling Language.Haskell.TH.Instances.Lift ( src/Language/Haskell/TH/Instances/Lift.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/TH/Instances/Lift.o )
[2 of 6] Compiling Language.Haskell.Meta.Syntax.Translate ( src/Language/Haskell/Meta/Syntax/Translate.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Syntax/Translate.o )
[3 of 6] Compiling Language.Haskell.Meta.Parse ( src/Language/Haskell/Meta/Parse.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Parse.o )
[4 of 6] Compiling Language.Haskell.Meta.Parse.Careful ( src/Language/Haskell/Meta/Parse/Careful.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Parse/Careful.o )
[5 of 6] Compiling Language.Haskell.Meta ( src/Language/Haskell/Meta.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta.o )
[6 of 6] Compiling Language.Haskell.Meta.Utils ( src/Language/Haskell/Meta/Utils.hs, dist/dist-sandbox-d2861272/build/Language/Haskell/Meta/Utils.o )
src/Language/Haskell/Meta/Utils.hs:67:1:
Duplicate instance declarations:
instance Typeable Q
-- Defined at src/Language/Haskell/Meta/Utils.hs:67:1
instance Typeable Q -- Defined in ‘Language.Haskell.TH.Instances’
src/Language/Haskell/Meta/Utils.hs:71:1:
Duplicate instance declarations:
instance Typeable QuasiQuoter
-- Defined at src/Language/Haskell/Meta/Utils.hs:71:1
instance Typeable QuasiQuoter
-- Defined in ‘Language.Haskell.TH.Instances’
Failed to install haskell-src-meta-0.6.0.9
...
haskell-src-meta-0.6.0.9 failed during the building phase. The exception was:
ExitFailure 1
interpolate-0.1.0 depends on haskell-src-meta-0.6.0.9 which failed to install.
However, if I proceed to type cabal install interpolate-0.1.0, the installation succeeds and I'm able to keep installing my project.
This is frustrating because I have to "manually" install several packages before I can get all my dependencies installed. The fact that the original installations fail with compiler errors seems to suggest that the compiler is configured differently somehow?
I'm using GHC 7.8.3 and cabal-install 1.22.4.0 (version 1.22.3.0 of the Cabal library). Many thanks for any help!
Actually it's not a problem with the version of haskell-src-meta but rather with the version of its dependency th-orphans.
haskell-src-meta (versions 0.6.0.8 and 0.6.0.9) has an upper bound th-orphans <0.12.
With --allow-newer you told Cabal to ignore version upper bounds, so Cabal decided to use th-orphans version 0.12.0, since it's newer and presumably better. But, in fact, haskell-src-meta really does not build with th-orphans version 0.12.0, as you found out.
Unrestricted use of --allow-newer is likely to run into this kind of problem in general. It's better to specify the packages whose upper bounds you want to ignore with --allow-newer=base,containers,..., though in some cases doing so can be rather tedious.
In the first sentence of your question you mentioned repeatable builds. If that is what you want, there is no substitute for simply recording the exact versions that you want of all of your direct and indirect dependencies.

How do you set up Haskell + ghc-mod on OS/X?

I first set up Haskell from https://www.haskell.org/platform/ but ghc-mod had problems with sandboxes and to update it I needed a newer cabal which needed a newer ghc. Or something like that. (https://stackoverflow.com/a/28049104/131227 ??)
So I deleted everything, and installed from http://ghcformacosx.github.io/.
Then some strange failure setting up a new sandbox was because something didn't properly have a dependancy for happy. (https://github.com/haskell-suite/haskell-src-exts/issues/14)
Ok. Installed happy. Now trying (again) to install ghc-mod and I get a giant mess (below).
Should I use http://www.stackage.org/?
I've seen some people mention ghc-pkg recache or cabal install cabal-install... Are those things I need to do?
Mess:
Resolving dependencies... Configuring ghc-mod-5.2.1.2... Building ghc-mod-5.2.1.2... Failed to install ghc-mod-5.2.1.2 Build log ( /Users/mark/.cabal/logs/ghc-mod-5.2.1.2.log ): Configuring ghc-mod-5.2.1.2... Building ghc-mod-5.2.1.2... Preprocessing library ghc-mod-5.2.1.2...
Language/Haskell/GhcMod/Convert.hs:1:51: Warning:
-XOverlappingInstances is deprecated: instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS [ 1 of 38] Compiling Language.Haskell.GhcMod.Read ( Language/Haskell/GhcMod/Read.hs, dist/build/Language/Haskell/GhcMod/Read.o ) [ 2 of 38] Compiling Language.Haskell.GhcMod.Cabal21 ( Language/Haskell/GhcMod/Cabal21.hs, dist/build/Language/Haskell/GhcMod/Cabal21.o ) [ 3 of 38] Compiling Language.Haskell.GhcMod.Cabal18 ( Language/Haskell/GhcMod/Cabal18.hs, dist/build/Language/Haskell/GhcMod/Cabal18.o ) [ 4 of 38] Compiling Language.Haskell.GhcMod.Cabal16 ( Language/Haskell/GhcMod/Cabal16.hs, dist/build/Language/Haskell/GhcMod/Cabal16.o ) [ 5 of 38] Compiling Language.Haskell.GhcMod.GHCChoice ( Language/Haskell/GhcMod/GHCChoice.hs, dist/build/Language/Haskell/GhcMod/GHCChoice.o ) [ 6 of 38] Compiling Language.Haskell.GhcMod.Error ( Language/Haskell/GhcMod/Error.hs, dist/build/Language/Haskell/GhcMod/Error.o )
Language/Haskell/GhcMod/Error.hs:12:1: Warning:
Module ‘Control.Monad.Error’ is deprecated:
Use Control.Monad.Except instead
Language/Haskell/GhcMod/Error.hs:40:10: Warning:
In the use of type constructor or class ‘Error’
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"
Language/Haskell/GhcMod/Error.hs:40:10: Warning:
In the use of type constructor or class ‘Error’
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead" [ 7 of 38] Compiling Language.Haskell.GhcMod.Utils ( Language/Haskell/GhcMod/Utils.hs, dist/build/Language/Haskell/GhcMod/Utils.o )
Language/Haskell/GhcMod/Utils.hs:15:1: Warning:
The import of ‘Control.Applicative’ is redundant
except perhaps to import instances from ‘Control.Applicative’
To import instances alone, use: import Control.Applicative()
Language/Haskell/GhcMod/Utils.hs:45:51: Warning:
In the use of ‘strMsg’
(imported from Language.Haskell.GhcMod.Error, but defined in Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead" [ 8 of 38] Compiling Language.Haskell.GhcMod.Types ( Language/Haskell/GhcMod/Types.hs, dist/build/Language/Haskell/GhcMod/Types.o ) [ 9 of 38] Compiling Language.Haskell.GhcMod.Gap ( Language/Haskell/GhcMod/Gap.hs, dist/build/Language/Haskell/GhcMod/Gap.o )
Language/Haskell/GhcMod/Gap.hs:256:18:
Not in scope: data constructor ‘ExposePackageId’
Perhaps you meant ‘ExposePackage’ (imported from DynFlags) cabal: Error: some packages failed to install: ghc-mod-5.2.1.2 failed during the building phase. The exception was: ExitFailure 1
After applying the accepted answer (which seemed to install ghc-mod), running gch-mod gives the following:
> ghc-mod check x.hs
cabal-helper-wrapper: Installing a private copy of Cabal, this might take a
while but will only happen once per Cabal version.
If anything goes horribly wrong just delete this directory and try again:
/Users/mark/.ghc-mod/cabal-helper
If you want to avoid this automatic installation altogether install version
1.22.0.0 of Cabal manually (into your user or global package-db):
$ cabal install Cabal-1.22.0.0
...In order, the following would be installed:
filepath-1.3.0.1 (latest: 1.4.0.0) (new version)
directory-1.2.2.1 (new version)
process-1.2.3.0 (reinstall) changes: directory-1.2.2.0 -> 1.2.2.1,
filepath-1.4.0.0 -> 1.3.0.1
Cabal-1.22.0.0 (latest: 1.22.2.0) (new version)
cabal: The following packages are likely to be broken by the reinstalls:
ghc-7.10.1
Cabal-1.22.2.0
Use --force-reinstalls if you want to install anyway.
cabal-helper-wrapper: Installing Cabal version 1.22.0.0 failed.
nYou have two choices now:
- Either you install this version of Cabal in your globa/luser package-db
somehow
n- Or you can see if you can update your cabal-install to use a different
version of the Cabal library that we can build with:
$ cabal install cabal-install --constraint 'Cabal > 1.22.0.0'
nTo check the version cabal-install is currently using try:
$ cabal --version
ghc-mod: readCreateProcess: /Users/mark/.cabal/libexec/cabal-helper-wrapper "/Users/mark/work/haskell/ixberg/dist" "entrypoints" "source-dirs" "ghc-options" "ghc-src-options" "ghc-pkg-options" "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" (exit 1): failed
Strangely, it wants the version of Cabal that is currently installed:
> cabal --version
cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library
Edit (August 2015) Better fix
A better command line tool for installing Haskell binaries and libraries by the awesome FPComplete group called stack means you can install ghc-mod with stack install ghc-mod (outside a project to make it global) and it will just work. The binary will be installed to ~/.local/bin and should be put on your path so your editor can find it.
I will leave the below for anyone who wishes to know what cabal Hell really meant.
Problem With DanielG's Fork
I asked on the Haskell reddit and NihillstDandy explained that the GHC for Mac OS X does not register the Cabal library. This is not true for your install from http://ghcformacosx.github.io/. It does register the Cabal library.
ghc-mod needs the cabal library to work, but it does not compile with the cabal library. Instead it compiles with cabal-helper and that looks to see if you have a registered version of the cabal library. If it does not find any then cabal-helper-wrapper will install a private copy and in this case it tired to install the same version as what cabal-install was compiled with, cabal-1.22.0.0.
When I installed DanielG's Fork it worked for my current project, but after testing it in other projects I am getting the same error you are. This is a problem with the fork and not Haskell (as far as I can tell).
Original Answer
So, while I was putting this post together ghc-mod was fixed for GHC-7.10. Thanks to DanielG!
git clone https://github.com/DanielG/ghc-mod
cd ghc-mod
cabal install -j4
And if you get errors that say "setup-Simple-Cabal-1.22.2.0-x86_64-osx-ghc-7.10.1: The program 'happy' version
>=1.17 is required but it could not be found."
cabal install happy -j4
The same for any other problems and it should work. (Although you have happy installed, so it should just work).
The rest of the post is on how to downgrade the cabal executable, also known as cabal-install, to version 1.20.0.3. Although you could really use this to downgrade to any version. Since there is a working fork of ghc-mod that works with GHC-7.10 and cabal-1.22 you do not need to downgrade to fix ghc-mod.
I'm just leaving the rest of the post up here since, unfortunately, this is a problem with Haskell as a whole. Halcyon and nix are ways to deal with Haskell's shortcomings in this regard.
How to downgrade Cabal in Haskell
When I wrote this post ghc-mod, nor any fork, compiled with GHC-7.10 and versions below 7.10 broke with cabal-1.22 sandboxes.
However, even if you compile ghc-mod with GHC-7.8.4 (the version before 7.10) and cabal-1.20.0.3 you still cannot use ghc-mod inside a sandbox created by cabal-1.22 and above. So the only way to use ghc-mod is to either downgrade your entire system to cabal-1.20.0.3 or don't use sandboxes. This means you can still use GHC-7.10, but you have to use the older version of cabal. That is unless you want to wait until the convener or someone else fixes it for GHC-7.10. Its been over a week already, but some kind Haskell programmer fixed it in a fork (see above).
If this is something you still want here is how to compile ghc-mod with GHC-7.8.4 and cabal-1.20.0.3. Also, I replace the executable cabal-1.22 with the older cabal-1.20.0.3. Note, it does not matter what directory you download the sources to.
download GHC-7.8.4 source for your OS from here
tar -xf path_to_zipped_source
cd path_to_ghc-7.8.4
The next steps will install ghc-7.8.4 as ghc-7.8.4 in the same folder as ghc-7.10 is install for you. The -j4 is to tell make to use 4 threads to compile it.
./configure
make install -j4
To get the correct version of cabal we can just ask cabal to get it.
cabal get cabal-install-1.20.0.3
cd cabal-install-1.20.0.3
Now to install cabal with ghc-7.8.4. Here cabal-1.22 will pull all the decencies and should give you some warning about installing another version of the cabal library (not to be confused with cabal-install), this should not cause problems.
cabal --with-compiler=ghc-7.8.4 install
So now you should have cabal-1.20.0.4 installed, but not on your path. It will be in ~/.cabal/bin. We need to make this global, so remove cabal-1.22 (it only removes the symlink).
rm `which cabal`
And create the symlink to cabal-1.20.0.4. Btw, you will need to remove any sandboxes you made with cabal-1.22 and remake them with cabal-1.20.0.4.
If you do not have realpath you can just type in the full path of cabal. I use it for connivence.
cd ~/.cabal/bin
ln -s `realpath cabal` /usr/local/bin
Now this is how I compiled ghc-mod on my mac (you may run into your own problems). I'm not sure why cabal couldn't do it in one call, but this worked in the end.
cabal --with-compiler=ghc-7.8.4 install happy
cabal --with-compiler=ghc-7.8.4 install haskell-src-exts-1.16.0.1
cabal --with-compiler=ghc-7.8.4 install hlint-1.9.19
cabal --with-compiler=ghc-7.8.4 install ghc-mod
Now you should be able to call ghc-mod from anywhere. To test it just type ghc-mod after you have cabal sandbox init. If it does not throw any errors then your in the clear.
The version of executable cabal that is used to configure this project should be the same as the version of the global Cabal package.
It's easier to install a compatible version of cabal-install than Cabal as follows:
$ ghc-pkg list | grep Cabal
Cabal-1.22.2.0
$ cabal install cabal-install-1.22.2.0
Or build one in sandbox and replace/shadow the original one.
Then don't forget to re-configure the project with the new cabal:
$ cabal clean && cabal configure
Now the ghc-mod should works.
If Cabal-1.22 isn't registered (ghc-pkg list cabal), the cabal-helper-wrapper will install a private copy because it needs the library installed to work, but it doesn't want to stomp on anything you have that might break by upgrading Cabal directly.
GHC for Mac OS X doesn't register the Cabal library, it comes bundled with a version of cabal-install built against it.

c2hs installation error with Mac OS X 10.7.5

I'm trying to install c2hs with cabal install c2hs.
I created ~/.cabal/bin to install the binary beforehand.
With the command cabal install c2hs to get the errors.
src/Control/StateTrans.hs:77:1: Warning:
Module `Prelude' does not export `catch'
[ 3 of 26] Compiling Data.Errors ( src/Data/Errors.hs, dist/build/c2hs/c2hs-tmp/Data/Errors.o )
[ 4 of 26] Compiling Data.Attributes ( src/Data/Attributes.hs, dist/build/c2hs/c2hs-tmp/Data/Attributes.o )
[ 5 of 26] Compiling Text.Lexers ( src/Text/Lexers.hs, dist/build/c2hs/c2hs-tmp/Text/Lexers.o )
[ 6 of 26] Compiling Control.StateBase ( src/Control/StateBase.hs, dist/build/c2hs/c2hs-tmp/Control/StateBase.o )
[ 7 of 26] Compiling Data.NameSpaces ( src/Data/NameSpaces.hs, dist/build/c2hs/c2hs-tmp/Data/NameSpaces.o )
[ 8 of 26] Compiling C2HS.C.Attrs ( src/C2HS/C/Attrs.hs, dist/build/c2hs/c2hs-tmp/C2HS/C/Attrs.o )
[ 9 of 26] Compiling C2HS.C.Builtin ( src/C2HS/C/Builtin.hs, dist/build/c2hs/c2hs-tmp/C2HS/C/Builtin.o )
[10 of 26] Compiling Paths_c2hs ( dist/build/autogen/Paths_c2hs.hs, dist/build/c2hs/c2hs-tmp/Paths_c2hs.o )
dist/build/autogen/Paths_c2hs.hs:21:13: Not in scope: `catch'
dist/build/autogen/Paths_c2hs.hs:22:13: Not in scope: `catch'
dist/build/autogen/Paths_c2hs.hs:23:14: Not in scope: `catch'
dist/build/autogen/Paths_c2hs.hs:24:17: Not in scope: `catch'
cabal: Error: some packages failed to install:
c2hs-0.16.5 failed during the building phase. The exception was:
ExitFailure 1
What is wrong with the installation? The ghc version is 7.6.3.
The install worked for me right now, on my Ubuntu box, so I can say for sure that c2hs isn't broken for everyone right now.
I think you might have version issues.... Try
cabal update
and try the install again.
In particular-
The function Prelude.catch was moved to Control.Exception.catch recently, see https://ghc.haskell.org/trac/ghc/ticket/4865. I downloaded the c2hs sources (using cabal unpack c2hs), and looked at what headers Paths_c2hs.hs needs (this seems to be the file with the import problems). This is what the imports section contained-
import qualified Control.Exception as Exception
import Data.Version (Version(..))
import System.Environment (getEnv)
import Prelude
(Paths_c2hs.hs is autogenerated, so I had to build it first).
Indeed, it was using Control.Exception. Because this is a module in base, you should have it, and probably just have out of date/mismatched packages. (In fact, my file's line numbers don't match your error message line numbers above- This is another indication we are using different versions, and I believe mine is up to date :) .)
Although I think that the "cabal update" will fix the problem, if not, try looking in these two places-
Does Control.Exception.catch exist in your base modules? Just try to compile an empty program with an dummy reference to catch, like this-
import Control.Exception
x = catch
main = undefined
Does your autogenerated Paths_c2hs.hs point to the correct catch function. Just use cabal to unpack, configure and build c2hs and then look at dist/build/autogen/Paths_c2hs.hs. (you will probably hit your error in the build phase, but given what you have shown above, it will happen after the Paths_c2hs.hs creation).
The issue was that I installed two different versions of ghc on my mac: one from brew install ghc and the other from haskell platform.
I had to install the newest version of haskell platform, but before doing that I also needed to uninstall old version uninstall-hs only VERSION and brew unistall ghc.
After reinstalling the newest haskell platform, the compilation works fine.
https://github.com/haskell/cabal/issues/1137
How to install Haskell cabal tool for Haskell 7.6.1 on Mac OSX?
Other method can be using brew brew install haskell-platform.

Cannot resolve the dependency about yesod-auth-oauth package

I want to use Yesod web framework with yesod-auth-oauth, but I encountered a dependency problem while cabal-dev install:
/Users/kenta/myapp/oryza% cabal-dev install
Resolving dependencies...
cabal: cannot configure yesod-platform-1.0.2. It requires data-default ==0.4.0
For the dependency on data-default ==0.4.0 there are these packages:
data-default-0.4.0. However none of them are available.
data-default-0.4.0 was excluded because authenticate-oauth-1.3.0 requires
data-default ==0.3.*
data-default-0.4.0 was excluded because data-default-0.3.0 was selected
instead
data-default-0.4.0 was excluded because oryza-0.0.0 requires data-default
==0.3.*
I don't have any idea of what's wrong.
What I did is just inserting one line in Cabal file:
yesod-auth-oauth >= 1.0 && < 1.1
The default scaffolding works fine, which is created through yesod init.
The version information
yesod-core: 1.0.1
cabal-dev: 0.9.1 (build with Cabal 1.14.0)
cabal-install: 0.10.2
GHC: 7.0.4
OS: Mac OS X Lion
Thanks.
This looks like an overly restrictive upper bound in the authenticate-oauth package. It would be best to follow up directly with the maintainer of that package.
In general, these kinds of issues are a side-effect of following the Package Versioning Policy. Basically, it's a trade-off between having these "refuse to compile" annoyances and more insidious "can't compile" problems.
I don't remember for sure, but I think my change to the cabal file for yesod-auth-oauth fixes this.

Resources