Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing IHaskell kernel for jupyter notebooks -lgmp cannot be found by Linker

I'm trying to install IHaskell in jupyter, directly from instructions here.

I ran the following.

sudo apt-get install -y python3-pip git libtinfo-dev libzmq3-dev libcairo2-dev libpango1.0-dev libmagic-dev libblas-dev liblapack-dev    
git clone https://github.com/gibiansky/IHaskell
cd IHaskell
pip3 install -r requirements.txt
stack install gtk2hs-buildtools
# stack install --fast
# ihaskell install --stack
# jupyter labextension install ihaskell_jupyterlab

I got this error on the 5th command above, the gtk2hs-buildtools one:

(envname) me@machine:~/plc/IHaskell$ stack install gtk2hs-buildtools
Linking /home/me/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 ...
/home/me/anaconda3/envs/envname/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
`x86_64-conda_cos6-linux-gnu-cc' failed in phase `Linker'. (Exit code: 1)

--  While building simple Setup.hs using:
      /home/me/.stack/programs/x86_64-linux/ghc-8.4.4/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-2.2.0.1 /home/me/.stack/setup-exe-src/setup-mPHDZzAJ.hs /home/me/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /home/me/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4
    Process exited with code: ExitFailure 1

Some searching told me cannot find -lgmp is solved by:

$ sudo apt-get install libgmp3-dev

I did this. This installed successfully, but

(envname) me@machine:~/plc/IHaskell$ stack install gtk2hs-buildtools

Still produces the same error. What's wrong and how do I fix it?

Update from scinart's suggestion

$ conda install gmp
Solving environment: done

## Package Plan ##

  environment location: /home/me/anaconda3/envs/envname

  added / updated specs: 
    - gmp


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    openssl-1.0.2p             |       h470a237_1         3.1 MB  conda-forge
    ca-certificates-2018.10.15 |       ha4d7672_0         135 KB  conda-forge
    certifi-2018.10.15         |        py36_1000         138 KB  conda-forge
    gmp-6.1.2                  |       hfc679d8_0         676 KB  conda-forge
    ------------------------------------------------------------
                                           Total:         4.0 MB

The following packages will be UPDATED:

    ca-certificates: 2018.03.07-0      --> 2018.10.15-ha4d7672_0 conda-forge
    certifi:         2018.10.15-py36_0 --> 2018.10.15-py36_1000  conda-forge
    openssl:         1.0.2p-h14c3975_0 --> 1.0.2p-h470a237_1     conda-forge

The following packages will be DOWNGRADED:

    gmp:             6.1.2-h6c8ec71_1  --> 6.1.2-hfc679d8_0      conda-forge

Proceed ([y]/n)? y


Downloading and Extracting Packages
openssl-1.0.2p       | 3.1 MB    | ######################################################################################################################################################################################################## | 100% 
ca-certificates-2018 | 135 KB    | ######################################################################################################################################################################################################## | 100% 
certifi-2018.10.15   | 138 KB    | ######################################################################################################################################################################################################## | 100% 
gmp-6.1.2            | 676 KB    | ######################################################################################################################################################################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Looks good!

(envname) me@machine:~/plc/IHaskell$ stack install gtk2hs-buildtools
Linking /home/me/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 ...
/home/me/anaconda3/envs/envname/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
`x86_64-conda_cos6-linux-gnu-cc' failed in phase `Linker'. (Exit code: 1)

--  While building simple Setup.hs using:
      /home/me/.stack/programs/x86_64-linux/ghc-8.4.4/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-2.2.0.1 /home/me/.stack/setup-exe-src/setup-mPHDZzAJ.hs /home/me/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /home/me/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4
    Process exited with code: ExitFailure 1

Darn, same error as before.

So, from this, you can see I had the gmp package installed, and in fact had had a higher version. The issue seems to be that gmp cannot be found by the linker for some reason (even though it is there), so reinstalling gmp will not help.

Update 2

Another thing I tried was:

$ conda install gxx_linux-64

recommended here, also didn't work.

Update 3

This also looked like the same issue, resolved that way, but did not work for me.

like image 303
Mittenchops Avatar asked Nov 03 '18 23:11

Mittenchops


2 Answers

Update 01/12/2019:

I recently re-installed latest anaconda (Anaconda3-2018.12-Linux-x86_64.sh). But this time did not install any gcc package on it (like gxx_linux-64) , nor add my specific env's bin directories to my $PATH (the snippet it installs in my .bashrc file seems to manage that) and the default IHaskell instructions went smooth, even while having conda my conda environment activated.


Original post:

For my purposes, i wanted IHaskell for jupyter to learn Haskell and take some notes while I did so. I also have conda via anaconda on my environment, used for other programming purpose, and got the same error you did above. So.... I set up a jupyter instance that was not based on conda, additionally and that seemed to do the trick.

I then installed jupyter as a global binary. In my case of Ubuntu Linux it was with sudo apt install jupyter-notebook . I then selectively deactivated conda in just the terminal window I was on with conda deactivate ; export PATH=/usr/bin:$PATH.

I also added a symlink to my local libgmp to make it more findable. I found that having a libgmp.so.3 symlink worked fine (even if it linked to a newer libgmp).

$ sudo ldconfig -p | grep libgmp
  libgmp.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgmp.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libgmp.so /usr/lib/libgmp.so.3
$

Then I downloaded stack from releases one with gmp (stack-1.9.3-linux-x86_64-gmp4.tar.gz) and put that in some directory, ~/apps/stack, that I added to to my $PATH , so i can invoke stack. From that point, with conda deactivated per command above, the instructions from IHaskell went smoother. I think i needed to add allow-newer: true for the optional stack install of gtk2hs-buildtools to work (YMMV).

And that was it, the haskell kernel was installed and ready for use:

$ which ihaskell
/home/yuvilio/.local/bin/ihaskell
$ ihaskell install --stack
$ jupyter kernelspec list
Available kernels:
  haskell      /home/yuvilio/.local/share/jupyter/kernels/haskell
...
$

And then eureka, it worked. I just used my globally installed jupyter-notebook and jupyter-console (with conda disabled in that terminal, per above) and the haskell kernel was available and working just dandy:

$ jupyter-console --kernel=haskell
Jupyter console 5.2.0
IHaskell 0.9.1.0 GHC 8.6.3
In [1]: sum[1..5]
:15
In [2]: double x = x + x
In [3]: double 3
:6

I'm sure there's a cleverer way to make IHaskell work with conda but it sounds like it was still in progress. The good thing about this setup is that on other terminal screens, my conda worked just fine as normal on other terminal sessions. This is not much of a production setup, but if you just want to make jupyter-notebooks with haskell content, this seems good enough to get going.

like image 85
yuvilio Avatar answered Nov 03 '22 05:11

yuvilio


Briefly, if, when you install ghc via stack, you have Anaconda enabled with gcc and ld in its environment then ghc will forever be broken. One workaround is to delete the ghc that stack installed, conda uninstall ... Anaconda's gcc (probably the gcc_linux-64 package) and ld (the binutils_linux-64 and binutils_impl_linux-64 packages), install ghc again (and then reinstall Anaconda's gcc and ld if you really want).

See https://github.com/haskell/cabal/issues/5280#issuecomment-718818157 for a more in depth analysis.

like image 24
Tom Ellis Avatar answered Nov 03 '22 05:11

Tom Ellis