Installing `ghc-mod` with Cabal - haskell

cabal install ghc-mod seems to work, but when I try cabal run ghc-mod I get the following error:
Package has never been configured. Configuring with default flags. If this fails, please configure manually.
cabal: No cabal file found.
Please create a package description file <pkgname>.cabal
The resources I've found seem to suggest that creating a package description file shouldn't be necessary to install a package.
Any ideas?

The standard way to install stuff on Haskell nowadays is within sandboxes.
Go to the terminal and create an empty folder that will house your ghc-mod sandbox. cd into that folder and:
cabal sandbox init
cabal install ghc-mod
After it finishes you will find the ghc-mod binary you seek within .cabal-sandbox/bin. Since it's statically linked it's safe to move it to somewhere in your $PATH.
I strongly encourage you use a sandbox but if you don't want to go to .cabal in your home directory and you will find the binary with bin

Related

Cabal install command Gives error

I can't understand why it just dosen't work. My question is what might have gone wrong i have created the ~/.bash_profile and tried to add the PATH given by the haskell webpage.
When i preform cabal install i get this output:
Marcuss-MacBook-Pro:~ marcuslagerstedt$ cabal install
cabal: Error reading local package.
Couldn't find .cabal file in: .
Marcuss-MacBook-Pro:~ marcuslagerstedt$
I hope i did a correct question.
But i really need help aswell.
You seem to be wanting to install a particular package, namely agda. The command cabal install takes either the name of a package or assumes you are installing some package in the local directory. You are hitting this second case.
To install agda try:
cabal update
cabal install agda

How to manually install package to a project that uses cabal

I was hoping to use a library that is on Hackage. But it turns out that the maintainer of the package has abandoned the library for some time and now it's not compiling due to minor problems. Now that I fixed the problems, what is the best way to link it with my cabal project until my PR is merged into the upstream
To install it like "cabal install ..." would install it, try this:
Use "cabal get pkgname-X.Y.Z" to get the source from Hackage; it places the source in the directory pkgname-X.Y.Z
cd into the source directory and apply your patches
Run cabal install
There are other options if you are using stack or cabal sandboxes.

What is the common workflow of using cabal for personal project?

Assume I want to creat my own local library called MyLib, my workflow is:
$ cabal init
# # edit the ".cabal" file, set the "exposed-modules" as "MyLib"
# # edit "MyLib.hs" located in "src"
$ cabal sandbox init
$ cabal install
So my question is
is my workflow an acceptable one, or could it be better?
now I have a compiled library in .cabal-sandbox/lib, how could I use it or import MyLib from my another haskell project? It seems that packages downloaded from hackage through cabal install are stored in ~/.cabal, while my own locally installed package is not there.
what is the difference between cabal build and cabal install, it seems that after running cabal build, I could already run my lib through cabal repl, so what extra jobs does cabal install do?
I've never used cabal sandbox so I can't speak much to it.
cabal build compiles your source code into your dist directory.
cabal install takes your compiled source code and sends it to your ~/.cabal directory, and registers it in your ~/.ghc directory. Now you can import it into other code just as you would any other library you've installed with cabal.
In my personal projects, I use cabal configure, cabal build, cabal repl, and cabal install. And configure is kind of optional.

Cabal install reports package as installed, but Setup configure reports it as missing

I am using ghc-7.6.3 with cabal-install version 1.18.0.5 using version 1.18.1.3 of the Cabal library. My operating system is Debian Wheezy 7.5.
I have a fresh cabal install, and that I have removed the .ghc from my home directory.
After that I have changed the cabal config file and set:
remote-repo: stackage-nightly-2014-12-15:http://www.stackage.org/snapshot/nightly-2014-12-15
After that I did (following this documentation)
$ cabal update
$ cabal install alex happy yesod-bin
and the build complained that it cannot build package system-filepath-0.4.12.
So, I am trying to build package system-filepath-0.4.12 manually. After unpacking the archive, I cd-ed to the unpacked folder and entered:
$ ghc -o Setup Setup.hs
$ ./Setup configure
which gives:
Configuring system-filepath-0.4.12...
Setup: At least the following dependencies are missing:
text >=0.7.1
But
$ cabal install text
gives:
Resolving dependencies...
All the requested packages are already installed:
text-1.1.1.3
Use --reinstall if you want to reinstall anyway.
How is it possible that a package is reported as installed and missing at the same time?
Should I look for a more stable remote-repo configuration, is there something I can check that might fix the missing text package? Note that I am not using a sandbox.
EDIT
Thanks for pointing out that there are two package databases.
I have now tried both
$ cabal configure
$ cabal build
and
$ Setup configure --user
$ Setup build
Both give no error during configuration, but give the following error during the build phase:
Building system-filepath-0.4.12...
Preprocessing library system-filepath-0.4.12...
/usr/bin/ld: cannot find -lHStext-1.1.1.3-ghc7.8.3
collect2: error: ld returned 1 exit status
Try this instead
cd system-filepath--0.4.12
cabal configure
I am not sure why, but this works for me, whereas Setup.hs gave me the same error (truth be told, I always do it the cabal configure way, and am not sure if your way should also work).
There are (at least) two package databases: a global one available to all users, and a user-specific one. By default, Setup.hs looks in (and installs to) the global one, and cabal-install looks in (and installs to) the user-specific one. You can manually choose one or the other with --user and --global; so, you could fix this either by using
./Setup configure --user
or by
cabal install text --global
You can see the current state of the package databases with ghc-pkg, which will report information about both by default.

cabal install bnfc missing directory

I'm new to Haskell, trying to write a program for compiler construction class.
I installed the haskell-platform package on my ubuntu 13.10, and then (without messing around with anything after installing haskell platform) tried to run the following command:
$ sudo cabal install bnfc
which results with:
Resolving dependencies...
Configuring BNFC-2.6.0.3...
cabal: The following installed packages are broken because other packages they
depend on are missing. These broken packages must be rebuilt before they can
be used.
package process-1.1.0.2 is broken due to missing package
directory-1.2.0.1-508733a890139bbedb8aa76468431462
Failed to install BNFC-2.6.0.3
cabal: Error: some packages failed to install:
BNFC-2.6.0.3 failed during the configure step. The exception was:
ExitFailure 1
As I try installing package directory it says the package is already installed.
Can anyone help?
I also am using Ubuntu 13.10 with the haskell platform package, and bnfc installs for me.
There are a few things you can check....
Don't use sudo with cabal install (by default cabal installs packages in your own home directory, using sudo might be causing trouble by giving the wrong file ownerships, or perhaps trying to put files in /root, or even overwriting /usr stuff)
Rename ~/.cabal/ and ~/.ghc/, and rebuild them by running "cabal update" (You may need to re-add ~/.cabal/bin/cabal from the moved location after the move). These hold installed packages and their info.... Since you have a new vanilla install, these should basically be empty, although the meta info in them may be corrupt. (if for some reason this makes things worse, you can always restore the original directory.... If it solves the problem, you can delete the original .cabal and .ghc)
You can get more info about why a package isn't installing by doing the following
cabal unpack bnfc #This will download and unpack the source code
cd BNFC-2.6.0.3 #enter the newly created source directory
cabal configure #This checks that all system dependencies are met
cabal build #This builds the package
cabal install #This installs the package in ~/.cabal/
(You may have to iterate to another package if a dependency isn't met)
I think 2. may solve your problem, as the error message you showed implies that the build process is hooked on finding a very specific version of the directory package, rather than the latest one. This happened to me once and cleaning out .cabal solved the problem for me.

Resources