Having difficulty installing ruby-filemagic gem on new RHEL6 server - ruby

It appears to be looking for the libmagic.so.1 file. I have that file. It is located in /usr/lib64. I am not running this installation as the root user.
I am also using rvm and Bundler. This is the result of my "bundle" command, when it gets to the ruby-filemagic line in my Gemfile:
[server#mine ext]$ ruby extconf.rb --with-magiclib
checking for magic_open() in -ltrue... no
*** ERROR: missing required library to compile this module
*** 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.
UPDATE:
Here are the results of the mkmf.log:
have_library: checking for magic_open() in -ltrue... -------------------- no
"gcc -o conftest -I. -I/usr/local/rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC conftest.c -L. -L/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -L. -rdynamic -Wl,-export-dynamic -lruby-static -ltrue -lrt -ldl -lcrypt -lm -lc"
conftest.c: In function ‘t’:
conftest.c:3: error: ‘magic_open’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once
conftest.c:3: error: for each function it appears in.)
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }
/* end */
"gcc -o conftest -I. -I/usr/local/rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC conftest.c -L. -L/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -L. -rdynamic -Wl,-export-dynamic -lruby-static -ltrue -lrt -ldl -lcrypt -lm -lc"
/usr/bin/ld: cannot find -ltrue
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { magic_open(); return 0; }
/* end */
I can't figure out what to do to make this work.

Had same problem on Ubuntu 12.04. Just installed libmagic-dev package through following command:
sudo apt-get install libmagic-dev

On a Mac, using homebrew:
sudo brew install libmagic

I needed to do:
yum install file-devel
That apparently contains the libmagic header files that the filemagic ruby gem required in order to compile. It worked like a champ after that.

I had the same problem on OpenSuse 11.3. This helped:
zypper install file-devel

Related

Mac 10.8.4 failed to install any native ruby gem extension

I have updated xcode to 5.1 and install the command line tools from preference->downloads page.
But when I try to install ruby gems (e.g. sqlite3, nokogiri), it gives errors like this:
*** 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.
And then I checked the mkmf.log:
" -o conftest -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0/x86_64-darwin13.0 -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0/ruby/backward -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -I/Users/travis/.sm/pkg/active/include -fPIC -mmacosx-version-min=10.7 -pipe -Wno-error=unused-command-line-argument-hard-error-in-future conftest.c -L. -L/Users/alun/.rvm/rubies/ruby-2.1.2/lib -lxml2 -arch x86_64 -lruby-static -framework CoreFoundation -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
I searched but didn't find similar mkmf.log
It seems the build command doesn't specify gcc or any other things.
Finally I've solved my problem, by reinstall xcode and command line tools, and then reinstall ruby with rvm

How to install gbarcode gem to Ubuntu?

I've problem with gbarcode gem which has dependency gnu-barcode c application.
When trying to say gem install gbarcode it says:
Building native extensions. This could take a while...
ERROR: Error installing gbarcode-linux:
ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.8.7-p357/bin/ruby extconf.rb
checking for main() in -lbarcode... yes
creating Makefile
make
gcc -I. -I. -I/home/user/.rvm/rubies/ruby-1.8.7-p357/lib/ruby/1.8/x86_64-linux -I. -fPIC -g -O2 -fPIC -c barcode_wrap.c
gcc -shared -o gbarcode.so barcode_wrap.o -L. -L/home/user/.rvm/rubies/ruby-1.8.7-p357/lib -Wl,-R/home/user/.rvm/rubies/ruby-1.8.7-p357/lib -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/user/.rvm/rubies/ruby-1.8.7-p357/lib -L/home/user/.rvm/rubies/ruby-1.8.7-p357/lib -lruby -lbarcode -lrt -ldl -lcrypt -lm -lc
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libbarcode.a(library.o): relocation R_X86_64_32 against `encodings' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libbarcode.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [gbarcode.so] Error 1
I've tried to install gnu-barcode application from ubuntu software center, apt-get and directly from source http://www.gnu.org/software/barcode/ and the response is always the same.
How should I install gnu barcode so that it's working with the gem.
And yes this project is quite heavy dependent on that gem so replacing it would be really painful to all parties.

Missing libstdc++ when installing taglib-ruby gem on Ubuntu 12.04?

I'm trying to install taglib-ruby but keep getting the same errors:
xyz#ubuntu:~$ sudo gem install taglib-ruby
Building native extensions. This could take a while...
ERROR: Error installing taglib-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
checking for main() in -lstdc++... no
You must have libstdc++ installed.
*** 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.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.9.1
--with-tag-dir
--without-tag-dir
--with-tag-include
--without-tag-include=${tag-dir}/include
--with-tag-lib
--without-tag-lib=${tag-dir}/lib
--with-stdc++lib
--without-stdc++lib
Gem files will remain installed in /var/lib/gems/1.9.1/gems/taglib-ruby-0.6.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/taglib-ruby-0.6.0/ext/taglib_base/gem_make.out
mkmf.log says the following:
have_library: checking for main() in -lstdc++... -------------------- no
"gcc -o conftest -I/usr/include/ruby-1.9.1/i686-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -I/usr/local/include -I/opt/local/include -I/sw/include -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L/usr/local/lib -L/opt/local/lib -L/sw/lib -L. -rdynamic -Wl,-export-dynamic -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
"gcc -o conftest -I/usr/include/ruby-1.9.1/i686-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -I/usr/local/include -I/opt/local/include -I/sw/include -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L/usr/local/lib -L/opt/local/lib -L/sw/lib -L. -rdynamic -Wl,-export-dynamic -lruby-1.9.1 -lstdc++ -lpthread -lrt -ldl -lcrypt -lm -lc"
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /*top*/
4: int main() {return 0;}
5: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */
"gcc -o conftest -I/usr/include/ruby-1.9.1/i686-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -I/usr/local/include -I/opt/local/include -I/sw/include -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L/usr/local/lib -L/opt/local/lib -L/sw/lib -L. -rdynamic -Wl,-export-dynamic -lruby-1.9.1 -lstdc++ -lpthread -lrt -ldl -lcrypt -lm -lc"
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /*top*/
4: int main() {return 0;}
5: int t() { main(); return 0; }
/* end */
--------------------
I followed the instructions in the readme, installing libtag1-dev and double checked if I had libstdc++ installed which I do (I even looked in the Ubuntu Software Center if I missed a file).
The only similar issue I found was this one but I already tried explictly defining the opt-dir and opt-include which didn't help either.
I have to admit that I am not really familiar with the topic or even Ubuntu, so it might as well be possible that I simply overlooked or totally missed something obvious about the error message.
Debian/Ubuntu: sudo apt-get install libtag1-dev
Fedora/RHEL: sudo yum install taglib-devel
Brew: brew install taglib
MacPorts: sudo port install taglib

Ruby Gems: Missing libraries or headers

I need to install a Ruby gem on my Debian server. This fails with an error message which is not very helpful to me as a non-ruby programmer. Can you help me diagnose the problem? What are the "necessary libraries and/or headers" that are missing?
root ~ # gem install schleuder
Building native extensions. This could take a while...
ERROR: Error installing schleuder:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
checking for magic_open() in -lmagic... no
*** ERROR: missing required library to compile this module
*** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.8
--with-magic-dir
--without-magic-dir
--with-magic-include
--without-magic-include=${magic-dir}/include
--with-magic-lib
--without-magic-lib=${magic-dir}/lib
--with-magiclib
--without-magiclib
Gem files will remain installed in /var/lib/gems/1.8/gems/ruby-filemagic-0.4.2 for inspection.
Results logged to /var/lib/gems/1.8/gems/ruby-filemagic-0.4.2/ext/gem_make.out
The logfile (assuming this is the right one) says:
root ~ # cat /var/lib/gems/1.8/gems/ruby-filemagic-0.4.2/ext/mkmf.log
have_library: checking for magic_open() in -lmagic... -------------------- no
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -rdynamic -Wl,-export-dynamic -lruby1.8-static -lmagic -lpthread -lrt -ldl -lcrypt -lm -lc"
conftest.c: In function ‘t’:
conftest.c:3: error: ‘magic_open’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once
conftest.c:3: error: for each function it appears in.)
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }
/* end */
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -rdynamic -Wl,-export-dynamic -lruby1.8-static -lmagic -lpthread -lrt -ldl -lcrypt -lm -lc"
/usr/bin/ld: cannot find -lmagic
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { magic_open(); return 0; }
/* end */
--------------------
Some Ruby gems come with "native extensions", meaning that they aren't entirely written in Ruby, but contain bindings to some external libraries written in C. Often this is for performance reasons, or so as to use well-established libraries rather than reinventing the wheel.
In your case it can't compile the native extension because the header files are missing. You probably need to install the libmagic-dev Debian package. Something like
sudo apt-get install libmagic-dev
would do the trick, depending on your package manager!

Compile postgres ruby gem against libpq.a on 10.6.7

I'm trying to install the ruby pg gem using a custom compiled postgres 8.4.7. This works as expected:
sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config
The gem compiles and installs correctly, and when required it loads the right dynamic library.
However, I'd like to statically link the gem for portability on multiple machines. My most reasonable attempt:
sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config --with-ldflags='-static'
fails with this error message:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-pg-config=/[edited]/pgsql-8.4.7/bin/pg_config --with-ldflags=-static
checking for /[edited]/pgsql-8.4.7/bin/pg_config... yes
MacOS X build: fixing architecture flags:
using the value in ARCHFLAGS environment variable ("-arch x86_64").
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
Any suggestion?
Thanks!
Update:
From the mkmf.log file:
conftest.c: In function ‘t’:
conftest.c:5: error: too few arguments to function ‘PQconnectdb’
checked program was:
/* begin */
1: #include
2:
3: /*top*/
4: int main() { return 0; }
5: int t() { PQconnectdb(); return 0; }
/* end */
Solved:
Copy Postgres static libraries to a separate location from the [prefix]/lib dir and pass the new path explicitly when building the gem:
sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config --with-pg-lib=/path/to/static/libs
Details:
The crucial information was a bit up in the mkmf.log file:
"gcc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/[edited]/pgsql-9.0.3/include -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -static -L/[edited]/pgsql-9.0.3/lib -lruby -lpq -lpthread -ldl "
ld: library not found for -lcrt0.o
collect2: ld returned 1 exit status
Passing the '-static' flag to the linker was trying to create a completely statically linked binary, which is not supported under Mac OS X:
Static linking of user binaries on Mac OS X

Resources