Build Gem Native Extension - linux

Passing on knowledge I just learned in the hopes of reducing the
headache others may experience with native gem extensions like I've
had.
TL;DR - Had an issue with bundle install. Read mkmf.log as mentioned in the error. The log had another error that I googled. Installed
necessary library. Afterwards, bundle install was successful.
Trying to install gems using bundler and getting errors about building gem native extensions:
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Installing daemons 1.2.3
Installing eventmachine 1.0.8 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/eventmachine-1.0.8/ext
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160309-8483-1so3k75.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
<...>
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/eventmachine-1.0.8/mkmf.log
extconf failed, exit code 1
<...>
Installing mysql2 0.4.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.4.3/ext/mysql2
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160309-8483-1oxfnj5.rb extconf.rb
checking for ruby/thread.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
<...>
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.4.3/mkmf.log
extconf failed, exit code 1
<...>
Installing rack 1.6.4
Installing tilt 2.0.1
Using bundler 1.11.2
An error occurred while installing eventmachine (1.0.8), and Bundler cannot continue.
Make sure that `gem install eventmachine -v '1.0.8'` succeeds before bundling.

Passing on knowledge I just learned in the hopes of reducing the
headache others may experience with native gem extensions like I've
had.
TL;DR - Had an issue with bundle install. Read mkmf.log as mentioned in the error. The log had another error that I googled. Installed
necessary library. Afterwards, bundle install was successful.
I see that the errors point me to mkmf.log and where it's located. I open it up and check the error. Among other things it mentions the following on lines 2 and 3.
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
I know from the error while during bundle install that it could be missing a library. So I search for a package called gmp. I find 2 libraries, one called libgmp10 and the other libgmp10-dev.
$ apt-cache search -n gmp
libgmp-dev - Multiprecision arithmetic library developers tools
libgmp10 - Multiprecision arithmetic library
<...>
I search my installed packages to see if I need to get one.
$ dpkg --get-selections | grep gmp
libgmp10:amd64 install
Since libgmp10 is already there, I try installing libgmp-dev. Then I run retry installing my gems, and it works!
$ sudo apt-get install libgmp-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libgmpxx4ldbl
Suggested packages:
libgmp10-doc libmpfr-dev
The following NEW packages will be installed:
libgmp-dev libgmpxx4ldbl
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 300 kB of archives.
After this operation, 1,675 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main libgmpxx4ldbl amd64 2:5.1.3+dfsg-1ubuntu1 [8,736 B]
Get:2 http://us.archive.ubuntu.com/ubuntu/ trusty/main libgmp-dev amd64 2:5.1.3+dfsg-1ubuntu1 [292 kB]
Fetched 300 kB in 0s (411 kB/s)
Selecting previously unselected package libgmpxx4ldbl:amd64.
(Reading database ... 218685 files and directories currently installed.)
Preparing to unpack .../libgmpxx4ldbl_2%3a5.1.3+dfsg-1ubuntu1_amd64.deb ...
Unpacking libgmpxx4ldbl:amd64 (2:5.1.3+dfsg-1ubuntu1) ...
Selecting previously unselected package libgmp-dev:amd64.
Preparing to unpack .../libgmp-dev_2%3a5.1.3+dfsg-1ubuntu1_amd64.deb ...
Unpacking libgmp-dev:amd64 (2:5.1.3+dfsg-1ubuntu1) ...
Setting up libgmpxx4ldbl:amd64 (2:5.1.3+dfsg-1ubuntu1) ...
Setting up libgmp-dev:amd64 (2:5.1.3+dfsg-1ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.7) ...
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using daemons 1.2.3
Installing eventmachine 1.0.8 with native extensions
Installing mysql2 0.4.3 with native extensions
Using rack 1.6.4
Using tilt 2.0.1
Using bundler 1.11.2
Installing rack-protection 1.5.3
Installing thin 1.6.4 with native extensions
Installing sinatra 1.4.6
Bundle complete! 3 Gemfile dependencies, 9 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

Related

Cabal install (Cabal cabal-install) fails due to missing zlib library

I want to install Cabal 3.4.0.0 on Ubuntu 20.04.
$ sudo apt install cabal-install
$ cabal --version
cabal-install version 2.4.0.0
$ sudo cabal update
$ sudo cabal install Cabal cabal-install
...
Starting zlib-0.6.2.3
Failed to install zlib-0.6.2.3
Build log ( /root/.cabal/logs/ghc-8.6.5/zlib-0.6.2.3-93Wbo8gIIzI9bg4p2MsNUF.log ):
cabal: Entering directory '/tmp/cabal-tmp-126381/zlib-0.6.2.3'
Configuring zlib-0.6.2.3...
cabal: Missing dependency on a foreign library:
* Missing (or bad) header file: zlib.h
* Missing (or bad) C library: z
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
...
cabal: Error: some packages failed to install:
cabal-install-3.4.0.0-3glzV3hM64DLoOfz3dHKsn depends on cabal-install-3.4.0.0
which failed to install.
hackage-security-0.6.0.1-KiAyVYLxooJAP3ckeQHnBD depends on
hackage-security-0.6.0.1 which failed to install.
zlib-0.6.2.3-93Wbo8gIIzI9bg4p2MsNUF failed during the configure step. The
exception was:
ExitFailure 1
The error says:
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version).
How can I install this package on Ubuntu 20.04?
You aim to install the cabal-install package. This package has a dependency that here produces a problem: the zlib package.
This zlib package is essentially a thin wrapper around the zlib C library [wikipedia]. As the error says however, you did not install the zlib library, or at least not its package where one can develop with the zlib library.
We can install this by installing the libghc-zlib-dev software package, for example with:
sudo apt-get install libghc-zlib-dev
If we inspect the package details on Debian, we see that essentially this is a package that will install the zlib1g-dev package, the package to develop software with the zlib library. We can thus decide to install libghc-zlib-dev, or zlib1g-dev with:
sudo apt-get install zlib1g-dev
Nixos Users append pkgs.haskellPackages.zlib to environment.systemPackages

Issue installing Snap on macOS Sierra

I'm having trouble installing the Haskell framework Snap on macOS Sierra. Whenever I install it, I get the following message:
Resolving dependencies...
Configuring securemem-0.1.9...
Configuring skein-1.0.9.4...
Configuring configurator-0.3.0.0...
Configuring cryptonite-0.24...
Building configurator-0.3.0.0...
Building securemem-0.1.9...
Building skein-1.0.9.4...
Failed to install configurator-0.3.0.0
Build log ( /Users/nicholas/.cabal/logs/ghc-8.2.1/configurator-0.3.0.0-6dySPcNCURWFswtMXJvzho.log ):
cabal: Entering directory '/tmp/cabal-tmp-66175/configurator-0.3.0.0'
Configuring configurator-0.3.0.0...
Preprocessing library for configurator-0.3.0.0..
Building library for configurator-0.3.0.0..
<command line>: cannot satisfy -package-id attoparsec-0.13.2.0-5dp4kBDsiGY4dQpLKbD5rk:
attoparsec-0.13.2.0-5dp4kBDsiGY4dQpLKbD5rk is unusable due to shadowed dependencies:
scientific-0.3.5.1-L0qYzdp0wpz8rO8gircNSR text-1.2.2.2-EGUst8sqNAZCw1xLPcmcMH
(use -v for more information)
cabal: Leaving directory '/tmp/cabal-tmp-66175/configurator-0.3.0.0'
Configuring transformers-base-0.4.4...
Building cryptonite-0.24...
Building transformers-base-0.4.4...
Installed securemem-0.1.9
Installed transformers-base-0.4.4
Installed skein-1.0.9.4
Installed cryptonite-0.24
Updating documentation index
/Users/nicholas/Library/Haskell/share/doc/x86_64-osx-ghc-8.2.1/index.html
cabal: Error: some packages failed to install:
configurator-0.3.0.0-6dySPcNCURWFswtMXJvzho failed during the building phase.
The exception was:
ExitFailure 1
snap-1.0.0.2-5CZKyA9EY4oLgkpHYCVfnv depends on snap-1.0.0.2 which failed to
install.
I'm using the Haskell Platform installed using homebrew (brew cask install haskell-platform), and cabal version 2.0.0.2. I have tried using sudo and deleting my ~/.ghc file
There was an issue with full 8.2.1 binary platform builds that's just been resolved: https://mail.haskell.org/pipermail/haskell-cafe/2017-October/127979.html
This was likely an instance of that.
(see also: GHC cannot find libraries on fresh install of Haskell-Platform)
This looks like a bug in Cabal 2 (or potentially GHC 8.2). See https://github.com/haskell/cabal/issues/4728. I'd recommend sticking to GHC 8.0.2 for the moment with either cabal 1.24 or Stack. I'm the case of Stack, the version won't matter, since it will use the Cabal version shipped with GHC.

Package libc6 is not installed

I have build LFS 8.0 and prepared a base linux system. I am installing package manager on that system. I have installed dpkg from a source package in it. After installing dpkg when i try to install any .deb package it throws an error along with the list of several dependencies. Among them also their are some dependencies related to gcc and glibc. Althought they are already installed in my LFS system. Have searched alot regarding this but could not find any helping material that why the package could not find its pre-req package even its already installed.
For example when i try to install zlib1g_1.2.8.dfsg-5_amd64.deb in lfs system, below mentioned error appears:
{
root [ /sources ]# dpkg -i zlib1g_1.2.8.dfsg-5_amd64.deb
Selecting previously unselected package zlib1g:amd64.
(Reading database ... 348 files and directories currently installed.)
Preparing to unpack zlib1g_1.2.8.dfsg-5_amd64.deb ...
Unpacking zlib1g:amd64 (1:1.2.8.dfsg-5) ...
dpkg: dependency problems prevent configuration of zlib1g:amd64:
zlib1g:amd64 depends on libc6 (>= 2.14); however:
Package libc6 is not installed.
dpkg: error processing package zlib1g:amd64 (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
zlib1g:amd64
}
Note: I have installed only dpkg. apt-get is not installed.
Any helping material regarding this is much appreciated.
Thanks
Though those libraries may be present on your system, they are not installed as deb packages and for dpkg they are missing. If you want to use dpkg, you will have to install all of those libraries as debs.

Haskell / Stack / Nix build fails, requiring pkg-config >= 0.9.0 and cairo >= 1.2.0, but latest versions are pkg-config 0.29.2 and cairo 1.15.4

I'm building a Haskell project using Stack and Nix and depending on the cairo library from Hackage.
When I build the project, I get an error: unable to find pkg-config >= 0.9.0 or cairo >= 1.2.0. However, the latest versions according to their websites are pkg-config 0.29.2 and cairo-1.15.4, and this is reflected in the Nix package manager as well.
On the other hand, there's
this article from 2006 announcing the release of Cairo 1.2.0, which further confuses the issue.
Questions
Why are the expected versions so wildly different from the published versions on nixpkgs and the pkg-config / cairo websites?
What advice do you have to get cairo to build on macOS (best case scenario: using Nix for system packages and Stack for Haskell packages)
Steps to reproduce:
> stack new cairo-test simple && cd cairo-test
# Now, to get Cairo
> stack install cairo
cairo-0.13.3.1: configure ...
Process exited with code: ExitFailure 1
Configuring cairo-0.13.3.1...
setup: The program 'pkg-config' version >=0.9.0 is required but it could not be found.
# This version doesn't seem to exist (not on the pkg-config website, either).
> nix-env -qaP pkg-config
nixpkgs.pkgconfig pkg-config-0.29.2
nixpkgs.pkgconfigUpstream pkg-config-0.29.2
# However, if installed, a new error:
> nix-env -i pkg-config
installing ‘pkg-config-0.29.2’
building path(s) ‘/nix/store/m4ks2si7b78757c1rc43r0833pxkvjb3-user-environment’
created 102 symlinks in user environment
> stack install cairo
setup: The pkg-config package 'cairo' version >=1.2.0 is required but
it could not be found.
# Again, this version doesn't seem to exist, either on the site on in `nixpkgs`
> nix-env -qaP cairo
nixpkgs.cairo cairo-1.14.8
# Installing it anyway, to see what the next error is
> nix-env -i cairo
installing ‘cairo-1.14.8’
building path(s) ‘/nix/store/dcx0in96wcd7yd8q71y93jd5306vag8g-user-environment’
created 112 symlinks in user environment
# Get the same version error now that Cairo is installed
setup: The pkg-config package 'cairo' version >=1.2.0 is required but it could not be found.
The issue is not the library version, 1.14.8 is greater than 1.2.0. The problem is that the cairo development files don't get linked into your environment, that is, $PKG_CONFIG_PATH is not set.
Three solutions:
Find the cairo-dev directory in /nix/store, and add it to PKG_CONFIG_PATH. E.g.,
$ cairodev=$(nix-store --query --outputs $(nix-instantiate '<nixpkgs>' -A cairo) | grep dev$)
$ export PKG_CONFIG_PATH=$cairodev:$PKG_CONFIG_PATH
Run stack from within a nix shell, nix-shell -p pkgconfig cairo.
Use stack's nix support, by adding the following to stack.yml:
nix:
enable: true
packages: [pkgconfig, cairo]
By installing Homebrew and then cairo with brew install cairo, I was able to build the project.
However, this installed Cairo version 1.14 — the same that Nix installed! When I inspect with brew info cairo, I see some more information:
cairo: stable 1.14.8 (bottled), devel 1.15.4, HEAD
==> Dependencies
Build: pkg-config ✘
Required: freetype ✔, fontconfig ✔, libpng ✔, pixman ✔, glib ✔
I tried installing these dependencies with Nix, and uninstalling Homebrew. No luck -- got a ton of linking errors. And so I re-installed Homebrew and it works again.
This isn't the nice, clean solution I was looking for (had to install an external package manager), but it does solve the problem for now.

Can't install sdl2 via cabal

I am trying to install helm. When I try to install it, however I get this error:
$ cabal install helm
Resolving dependencies...
Configuring sdl2-1.1.0...
cabal: The pkg-config package 'sdl2' version >=2.0.3 is required but it could
not be found.
Failed to install sdl2-1.1.0
cabal: Error: some packages failed to install:
helm-0.6.1 depends on sdl2-1.1.0 which failed to install.
sdl2-1.1.0 failed during the configure step. The exception was:
ExitFailure 1
When I go to install sdl2 by itself, I get a similar message.
$ cabal install sdl2
Resolving dependencies...
Configuring sdl2-1.1.0...
cabal: The pkg-config package 'sdl2' version >=2.0.3 is required but it could
not be found.
Failed to install sdl2-1.1.0
cabal: Error: some packages failed to install:
sdl2-1.1.0 failed during the configure step. The exception was:
ExitFailure 1
I don't understand. According to Hackage, sdl2 is at version 1.1, but installing it requires version 2.0.3? I've tried this in and out of a sandbox. Results of ghc-pkg list are here if you think they're relevant: http://pastebin.com/tFrsfPFe
I'm on Ubuntu btw.
Help?
Another thing which could happen (happened to me) for other installs is that the PKG_CONFIG_PATH variable might not point to the package config file (sdl2.pc, for me in the /usr/local/lib/pkgconfig directory). pkg-config uses some default directories ('/usr/lib/pkgconfig' and '/usr/share/pkgconfig'), but if the sdl.pc file isn't in one of these, you'll have to specify the directory in the environment variable. You can check this with echo $PKG_CONFIG_PATH
If it turns out you need to set the variable, just use export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig (or to whatever directory your sdl2.pc file lives in)
I ran into the same problem, and I just want to add my solution here for the record. The native sdl2 libraries need to be installed first by following the directions here: https://github.com/haskell-game/sdl2#building

Resources