ERROR: failed to build gem native extension, Linux virtual machine - ruby

I'm running Ruby 2.0.0p645 on a Linux AWS.
I tried running gem install mechanize, but got this error:
Building native extensions. This could take a while...
ERROR: Error installing mechanize:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.0 extconf.rb
checking for main() in -lstdc++... no
creating Makefile
make "DESTDIR="
g++ -I. -I/usr/include/ruby/2.0 -I/usr/include/ruby/2.0/ruby/backward -I/usr/include/ruby/2.0 -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -mtune=generic -m64 -o unf.o -c unf.cc
make: g++: Command not found
make: *** [unf.o] Error 127
Gem files will remain installed in /path/to/.gem/ruby/2.0/gems/unf_ext-0.0.7.1 for inspection.
Results logged to /path/to/.gem/ruby/2.0/gems/unf_ext-0.0.7.1/ext/unf_ext/gem_make.out
How do I fix this so I can install mechanize on my virtual box?

Looks like you might need to install libstdc++. For Debian or Ubuntu try:
sudo apt-get install build-essential libstdc++6
and then retry installing the gem.

Related

Failed to install gem rest-client

I am trying to install gem res-client in my redhat linux server.Installed whatever dependencies i found but still not working for me.
Ruby Version:
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
[root#feeds ]# gem install rest-client
Building native extensions. This could take a while...
ERROR: Error installing rest-client:
ERROR: Failed to build gem native extension.
current directory: /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-0.0.7.6/ext/unf_ext
/opt/rh/rh-ruby23/root/usr/bin/ruby -I /opt/rh/rh-ruby23/root/usr/local/share/ruby/site_ruby -r ./siteconf20190429-62674-e4of20.rb extconf.rb
checking for main() in -lstdc++... no
creating Makefile
current directory: /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-
0.0.7.6/ext/unf_ext
make "DESTDIR=" clean
rm -f
rm -f unf_ext.so *.o .bak mkmf.log ..time
current directory: /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-0.0.7.6/ext/unf_ext
make "DESTDIR="
g++ -I. -I/opt/rh/rh-ruby23/root/usr/include -I/opt/rh/rh-ruby23/root/usr/include/ruby/backward -I/opt/rh/rh-ruby23/root/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -m64 -o unf.o -c unf.cc
make: g++: Command not found
make: *** [unf.o] Error 127
make failed, exit code 2
Gem files will remain installed in /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-0.0.7.6 for inspection.
Results logged to /opt/rh/rh-ruby23/root/usr/local/lib64/gems/ruby/unf_ext-0.0.7.6/gem_make.out
Can anyone please suggest.
Thanks
Sina
It looks like you are missing the gcc-c++ compiler. Install it with:
yum install gcc-c++
build-essential g++ are the missing ones. So try installing:
yum install build-essential g++
then install the required gem:
gem install rest-client
hope it helps....
Thanks .
I reinstall ruby and dependencies then it worked.
Regards,
Sina

Failing to install ruby gem "yajl-ruby"

I am trying to install the ruby gem "yajl ruby". I'm running Mac OS 10.7.4 and Ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]. When I run:
sudo gem install yajl-ruby
I get the following output:
Building native extensions. This could take a while...
ERROR: Error installing yajl-ruby:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
creating Makefile
make
gcc -I. - I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -arch i386 -arch x86_64 -g -Os -pipe - fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common -Wall -funroll-loops -c yajl.c
make: gcc: No such file or directory
make: *** [yajl.o] Error 1
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/yajl-ruby-1.1.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/yajl-ruby-1.1.0/ext/yajl/gem_make.out
What do I need to do in order to make the install work?
Try this:
$ sudo ln -s /usr/bin/llvm-gcc /usr/bin/gcc-4.2
It's a bit roundabout, but have you considered using RVM to manage your Ruby versions? As this you're working on an OS X box, I'm assuming it's your dev machine and so having a system-wide gem probably isn't as big a deal. RVM changes the paths for installing gems to be relative to the Ruby version in use and, as the paths are local to your user directory, you don't need to use sudo and thus avoid potential permission errors which is what I suspect is happening here.
I say I suspect it's a permission error because the missing file suggests something wasn't written to where it's expected to be. It's just a shot in the dark, though. Alternatively, you could try actually su'ing to root and doing the gem install there, but that's ugly.
I had a similar error installing yajl-ruby.
The error was that /Developer/usr/bin wasn't available. Doing an "ln -s /Applications/Xcode.app/Contents/Developer/usr/ /Developer/usr" fixed the error.
Here is the specific error I was seeing:
gem install yajl-ruby
Building native extensions. This could take a while...
ERROR: Error installing yajl-ruby:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
creating Makefile
make
xcrun cc -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common -Wall -funroll-loops -c yajl.c
sh: /Developer/usr/bin/xcodebuild: No such file or directory
/Developer/usr/bin/xcodebuild fails with 32512 - Unknown error: 32512
make: *** [yajl.o] Error 69
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/yajl-ruby-1.1.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/yajl-ruby-1.1.0/ext/yajl/gem_make.out

RVM - can not install gem thrift on Ubuntu 11.10

I use Ubuntu 11.10 and ruby 1.9.2
I can not install thrift gem on my machine
$ gem install thrift --no-ri --no-rdoc
Building native extensions. This could take a while...
ERROR: Error installing thrift:
ERROR: Failed to build gem native extension.
/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for strlcpy() in string.h... no
creating Makefile
make
gcc -I. -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -fPIC -g -O2 -Wall -Werror -o thrift_native.o -c thrift_native.c
gcc -I. -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -fPIC -g -O2 -Wall -Werror -o memory_buffer.o -c memory_buffer.c
gcc -I. -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -fPIC -g -O2 -Wall -Werror -o struct.o -c struct.c
struct.c:28:1: error: static declaration of ‘strlcpy’ follows non-static declaration
/home/sayuj/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/missing.h:157:20: note: previous declaration of ‘strlcpy’ was here
make: *** [struct.o] Error 1
Gem files will remain installed in /home/sayuj/.rvm/gems/ruby-1.9.2-p290/gems/thrift-0.7.0 for inspection.
Results logged to /home/sayuj/.rvm/gems/ruby-1.9.2-p290/gems/thrift-0.7.0/ext/gem_make.out
What went wrong and how to fix? All your support willbe highly appreciated. thanks!
I found some references to this issue on an Apache forum. There is a patch file there that it looks like you can run in order to get the thrift gem to install. I checked it over and it looks sound.
You can find it here:
https://issues.apache.org/jira/browse/THRIFT-1382

Ruby DevKit in cygwin not working

Im trying to install gems that require the ruby DevKit to be installed. E.g:
gem install sqlite3
This is the output:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby.exe extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... yes
checking for sqlite3_next_stmt()... yes
checking for sqlite3_backup_init()... yes
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... yes
checking for sqlite3_load_extension()... yes
creating Makefile
make
gcc -I. -I/usr/local/include/ruby-1.9.1/i386-cygwin -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -DHAVE
_RB_PROC_ARITY -DHAVE_SQLITE3_INITIALIZE -DHAVE_SQLITE3_NEXT_STMT -DHAVE_SQLITE3_BACKUP_INIT -DHAVE_SQLITE3_ENABLE_LOAD_EXTENSION -DHAVE_SQL
ITE3_LOAD_EXTENSION -I/usr/local/include -I/opt/local/include -I/sw/local/include -I/usr/include -O3 -g -Wall -Wno-unused-parameter -Wno-
parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long -o backup.o -c backup.c
make: gcc: Command not found
make: *** [backup.o] Error 127
Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.3 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.3/ext/sqlite3/gem_make.out
I do have make and gcc installed and don't understand why it's complaining that a command can't be found.
This happens not only if i try to install the sqlite3 gem but also other gems that require de devkit to be installed.
The DevKit is for the MingW port of YARV, not the Cygwin port. The Cygwin port doesn't need the DevKit, since Cygwin itself already contains all the necessary tools, libraries, and headers.

How to install Nokogiri as a Macruby gem?

The latest MacRuby release notes (v0.6) state that the authors have managed to get this release working with the SQLite and Nokogiri gems. However when I run sudo macgem install nokogiri I get the following errors:
ERROR: Error installing nokogiri:
extconf failed:
and then a bunch of paths followed by:
libxml2 is missing. try 'port install libxml2' or 'yum install libxml2'
/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib/ruby/Gems/1.9.0/gems/nokogiri-1.4.1/ext/nokogiri/extconf.rb:1:in `<main>': libxml2 is missing. try 'port install libxml2' or 'yum install libxml2' (SystemExit)
Anyone knows how to get this working? My platform is Mac OS X 10.6.3. Nokogiri normally (meaining on plain old ruby 1.8.7) installs without a problem.
Progress
OK, so I have:
git clone http://github.com/tenderlove/nokogiri.git
cd nokogiri/ext/nokogiri
Then I've rebuilt the macports libraries with sudo port upgrade --enforce-variants libxml2 +universal and sudo port upgrade --enforce-variants libxslt +universal
Then I've executed macruby extconf.rb successfully
Then I proceed to make
At this point it errors out like so:
/usr/bin/gcc -I. -I/opt/local/include/libxml2 -I/opt/local/include/ -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/universal-darwin10.0 -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/ruby/backward -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0 -I. -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS -I/opt/local/include/ -I/opt/local/include/libxml2 -I/opt/local/include -fno-common -fexceptions -fno-common -pipe -O3 -g -Wall -Wno-parentheses -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -arch i386 -arch x86_64 -o html_document.o -c html_document.c
In file included from ./html_document.h:4,
from html_document.c:1:
./nokogiri.h:35:16: error: st.h: No such file or directory
In file included from ./html_document.h:4,
from html_document.c:1:
./nokogiri.h:35:16: error: st.h: No such file or directory
lipo: can't open input file: /var/folders/wU/wUGgoG1JGeKBgwalWLPMAU+++TI/-Tmp-//ccSgAUv5.out (No such file or directory)
make: *** [html_document.o] Error 1
I think you have to build from source since only Nokogiri's head is MacRuby compliant
If you use the source code of GitHub,
$ git clone git://github.com/tenderlove/nokogiri.git
$ cd nokogiri/ext/nokogiri/
$ sed -i.bak 's/<st.h>/<ruby\/st.h>/' nokogiri.h
If you make a gem package of Nokogiri,
$ cd ../..
$ sudo gem install hoe
$ sudo gem install rake-compiler
$ sudo gem install racc
$ sudo gem install rexical
$ mkdir ~/.rubyforge; touch ~/.rubyforge/user-config.yml
$ rake gem
An Above command, I used ruby of the system default. ("/usr/bin/ruby")
$ cd pkg
$ sudo macgem install nokogiri-1.4.1.gem
I think you have to build a libxml2 as Universal binary.
If you use MacPorts, execute the command below.
$ sudo port upgrade --enforce-variants libxml2 +universal
$ sudo port upgrade --enforce-variants libxslt +universal
$ sudo port upgrade --enforce-variants sqlite3 +universal
It still fails in the installation (x _ x;
$ sudo macgem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
make failed:
["/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/bin/macruby extconf.rb", "checking for iconv.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for libxml/parser.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for libxslt/xslt.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for libexslt/exslt.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for xmlParseDoc() in -lxml2... yes\nchecking for xsltParseStylesheetDoc() in -lxslt... yes\nchecking for exsltFuncRegister() in -lexslt... yes\nchecking for xmlRelaxNGSetParserStructuredErrors()... yes\nchecking for xmlRelaxNGSetParserStructuredErrors()... yes\nchecking for xmlRelaxNGSetValidStructuredErrors()... yes\nchecking for xmlSchemaSetValidStructuredErrors()... yes\nchecking for xmlSchemaSetParserStructuredErrors()... yes\ncreating Makefile\n", "make", "/usr/bin/gcc -I. -I/opt/local/include/libxml2 -I/opt/local/include/ -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/universal-darwin10.0 -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/ruby/backward -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0 -I. -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS -I/opt/local/include/ -I/opt/local/include/libxml2 -I/opt/local/include -fno-common -fexceptions -fno-common -pipe -O3 -g -Wall -Wno-parentheses -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -arch i386 -arch x86_64 -o html_document.o -c html_document.c\nIn file included from ./nokogiri.h:75,\n from ./html_document.h:4,\n from html_document.c:1:\n./xml_document.h:5:16: error: st.h: No such file or directory\nIn file included from ./nokogiri.h:75,\n from ./html_document.h:4,\n from html_document.c:1:\n./xml_document.h:5:16: error: st.h: No such file or directory\nlipo: can't open input file: /var/tmp//cco5nNYw.out (No such file or directory)\nmake: *** [html_document.o] Error 1\n"]
I uploaded to GitHub which I made a package.
http://wiki.github.com/Watson1978/nokogiri-macruby/

Resources