Haskell: Failed to load interface for 'Graphics.Gloss' - haskell

Haskell Community.
I am a newbie in Haskell, can only implement simple Haskell functions.
I tried out one Haskell game program that was open source. While running it, GHC gave the following errors:
HexDame.hs:1:1: error:
Failed to load interface for ‘Graphics.Gloss’
Perhaps you meant
Graphics.GL (from OpenGLRaw-3.1.0.0)
Graphics.GL.HP (from OpenGLRaw-3.1.0.0)
Graphics.GL.NV (from OpenGLRaw-3.1.0.0)
Use -v to see a list of the files searched for.
HexDame.hs:2:1: error:
Failed to load interface for ‘Graphics.Gloss.Interface.Pure.Game’
Use -v to see a list of the files searched for.
HexDame.hs:3:1: error:
Failed to load interface for ‘Graphics.Gloss.Data.Extent’
Use -v to see a list of the files searched for.
I am unsure whether Gloss is installed or not. I am using GHC on Windows on a proxy network. The 'cabal update' solution is also not working.
For other information, I had downloaded the entire Haskell package from the website, so I presume it includes all necessary packages, including GLUT.
Please suggest solutions.

Related

How do I use the custom prelude from NoRedInk with stack?

I'm trying to write a desktop program using an elm frontend with haskell backend.
To make writing the backend code idiomatically similar to the front end code (and make sending data between them easier), it would be great to use No Red Ink's custom prelude.
Stack is my build tool.
It's the first time I've tried to use a custom prelude. I can't get it to even turn up. The key unresolvable error message for me is the one with no suggested "different approaches to resolving this":
In the dependencies for nri-prelude-0.6.0.6:
unix is a library dependency, but the package provides no library`
Here's everything I tried:
I tried adding -fplugin=NriPrelude.Plugin to my ghc options in my stack.yaml but it said
<command line>: Could not find module `NriPrelude.Plugin'
So I tried adding nri-prelude to my dependencies, resulting in a recommendation to add
- nri-prelude-0.6.0.6#sha256:4ccc7488149a0401a9241c9b64db22c48a8639afaae11cffb263da5226e8acde,5289
to my stack.yaml, which resulted in a recommendation to add
- terminfo-0.4.1.5#sha256:4d1790aeb354797955ca1cb67035ca80f66a0d9cc4e43a51c1c9d566e00ce350,1713
- unix-2.7.3#sha256:20079c504d0ca33fbf11de3a215d25220c8d43499a93049a8f2791323f3bd57b,6047
as well. This was a dead end for me because I got the error message:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for nri-prelude-0.6.0.6:
unix is a library dependency, but the package provides no library
needed due to Experiment-0.1.0.0 -> nri-prelude-0.6.0.6
Some different approaches to resolving this:
Plan construction failed.
I couldn't help but notice the empty list of approaches to resolving it this time.
Instead of going down that route I tried using a route that had worked for another library, by putting
- github: NoRedInk/haskell-libraries
commit: a202da122192ad2b9435f92086f5b4c5e304531b
in my stack.yaml. It didn't like that:
No cabal file found for Archive from https://github.com/NoRedInk/haskell-libraries/archive/a202da122192ad2b9435f92086f5b4c5e304531b.tar.gz
and when I tried
- github: NoRedInk/haskell-libraries/nri-prelude
commit: 8657ef0ea153a12fcaa0d048be98598512fe9df6
that didn't even parse:
Could not parse 'stack.yaml':
Aeson exception:
Error in $['extra-deps'][3]: failed to parse field 'extra-deps': parsing Text failed, expected String, but encountered Object
See http://docs.haskellstack.org/en/stable/yaml_configuration/

How do you pull library dependencies of binary you want to package using snapcraft

I am trying out the new linux packaging tool http://snapcraft.io/create/
It does have some documentation but it's not very mature and doesn't contain everything.
What I am trying to do is to generate a package for my binary that is compiled using Qt framework, thus it depends on a load of .so files. I couldn't find in documentation any way to convince snapcraft to pull all these dependencies and add them to the program hierarchy (the mounted squashfs).
So in order to "temporarily fix that" I hacked a very lame shell script that executes ldd on my binary and does this on its own. That "sort of" works because now indeed all the necessary libraries are in the image, but the program can't find them, because most of them have own paths and are not in root lib folder /usr/lib
The example of error I am getting when I try to start my program is:
/snap/huggle/x1/usr/bin/huggle: error while loading shared libraries: libGL.so.1: cannot open shared object file: No such file or directory
But the library is there:
/snap/huggle/x1/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1
It just has no clue how to find it. On other hand, given that snapcraft is advertised as awesome simple stupid packaging tool, I find it quite weird that something so simple as packaging a C++ binary would be so complicated. How should I do this properly?

How to find source code of module I am importing

How do I find the source of the code I am importing. Like if I do
λ <Prelude>: import Graphics.EasyPlot
λ <Prelude Graphics.EasyPlot>:
How do I find that code. I do not mean an online copy of the code (Google is very good at indexing Hackage by that) but where it is on my system that I can edit. The reason is that it is a bit buggy, and I want to try and fix it. (I might submit a patch, but I just want to fix it for my own use first.)
As #ThomasDuBuisson mentioned, you many not necessarily find that on your system. One thing which I generally do is fetch it using cabal:
cabal fetch package-name
It downloads the tarballs of the package. Once you have fetched it, the entire source will be under the path where cabal puts it. In my case, it is (/home/sibi/.cabal/packages/hackage.haskell.org/package-name ). You can then untar and then build it from the cabal file which is already present there.
That being said you should probably using the version control system which the project is using as #bheklilr pointed out.

Resolving GHC 'I found a duplicate definition for symbol ...'

When running Haskell programs that import several packages like this one:
import Text.Feed.Import
import Network.HTTP
main = do
page <- simpleHTTP (getRequest "http://stackoverflow.com")
print $ page
I get an error like this one (Note: This question intends to solve the general problem, this specific case is just an example) :
GHCi runtime linker: fatal error: I found a duplicate definition for symbol get_current_timezone_seconds
whilst processing object file
/usr/lib/ghc/time-1.4.0.1/HStime-1.4.0.1.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry
Reinstalling the packages (e.g. HTTP and feed in the above case) as described in this previous post doesn't help. How can I resolve this issue?
Why this error occurs
This issue is not specific to a single package (e.g. it was described here in relation to Yesod three years ago), but is caused by the different libraries you import (e.g. HTTP and feed) linking to different versions of a single library (this issue occurs only for libraries that export C-style symbols. Their symbol names are not unique. time is one of those packages.).
As denoted in the error message, the library that causes the issues in this specific case is time-1.4.0.1.
Diagnosing the exact problem
First, you need to identify which different versions exist of your library. You can do this by checking the packages using ghc-pkg describe <packagename>, or just take a look into your cabal installation directory (usually ~/.cabal/lib).
At the time of writing this, the issue was caused by both time-1.4.0.1 and time-1.4.1 being installed. By using ghc-pkg describe I figured out that feed (and only feed, in my case), linked to time-1.4.1 whereas about 100 libraries linked to time-1.4.0.1.
How to resolve
Identify the library version (of the library that causes the error, as denoted in the error message) as described above that fewer packages depend on. You'll need to rebuild all packages that depend on it. In my case this is time-1.4.1.
Then, uninstall the package:
$ ghc-pkg unregister time-1.4.1 --force
unregistering time-1.4.1 would break the following packages: feed-0.3.9.2 (ignoring)
Note that the feed package is now broken and needs to be rebuilt and reinstalled. After rebuilding however, it won't link to time-1.4.1 but time-1.4.0.1 (in my specific case). This re-linking will resolve the duplicate symbol problem.
$ cabal install feed
If the error still occurs after that, re-check all dependencies as described above. You need to make sure any library you import will show the same library it's linked to when analyzed with ghc-pkg describe <pkg>
Update: In order to find out, which packages depend on the problematic library, simply use ghc-pkg unregister without the --force flag (Thanks to John J. Camilleri for pointing that out!). Note that if no packages depend on said problematic package, it will be removed.
An alternative cause of the same problem, is when using common symbols in an external library, on windows. I have an issue with a fortran code base using the common symbols. It is better explained here> https://gitlab.haskell.org/ghc/ghc/-/issues/6107
This only happens in dynamic linking, so ghc works, but ghci does not.

Haskell linux install a module without cabal

I have developed a module (M.hs) which depends upon 3 other modules (A.hs, B.hs and C.hs). Now I want to use the module M across multiple other projects. So I have to install this module. But for learning purpose I don't want to use cabal, I want to do it manually. I want to install it in my home dir.
What is a proper course of action? Which files to be created, copied? where? How to use this module in other project?
Additional info:
I am using Debian 6
I am using GHC 6.12
You say you don’t want to use cabal, but would you use Cabal?
cabal is the name of the command line tool provided by cabal-install which can download packages from Hackage and resolve dependencies.
Cabal is the library that Haskell code uses to drive the compilation (e.g. pre-process files, build in the right order, build variants, generate documentation) and install into the right location.
I would not recommend not using Cabal, even for learning purposes, until you want to write a replacement for it. But if you really want to do it, here is the rough outline, with enough details to figure out for a good learning experience:
Build your files with -package-name yourpkgname-version.
Link the generated files to form a libyourpkgname-version.a file.
Create a package configuration file like /var/lib/ghc/package.conf.d/mtl-2.1.2.conf, and pay attention to name, `exposed-modules, import-dirs, library-dirs and hs-libraries
Register package by passing it to ghc-pkg register

Resources