How to install Nokogiri as a Macruby gem? - ruby

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/

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

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

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.

Homebrew / TinyTDS / FreeTDS bundle error

I used homebrew (linux port) to install freeTDS and am trying to deploy /bundle install my app with gem tinytds. I get this error output when doing bundle install
Installing tiny_tds (0.5.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/deployer/.rbenv/versions/1.9.2-p290/bin/ruby extconf.rb
/usr/bin/ld: /opt/homebrew/lib/libsybdb.a(dblib.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/opt/homebrew/lib/libsybdb.a: could not read symbols: Bad value
Pretty similar to this fix, but I don't have the files referred to in my folder: https://stackoverflow.com/a/7119224/1130736
Contents of homebrew lib folder:
/opt/homebrew/lib$ ls
libct.a libsybdb.a
Full error dump:
full error dump:
Installing tiny_tds (0.5.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/deployer/.rbenv/versions/1.9.2-p290/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... yes
checking for sybfront.h... yes
checking for sybdb.h... yes
checking for tdsdbopen() in -lsybdb... yes
checking for ct_bind() in -lct... yes
creating Makefile
make
/usr/bin/gcc -I. -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1 -I. -DHAVE_ICONV_OPEN -DHAVE_SYBFRONT_H -DHAVE_SYBDB_H -I/opt/homebrew/include -I/usr/local/include -I/usr/include -I'/home/deployer/.rbenv/versions/1.9.2-p290/include' -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -o client.o -c client.c
client.c: In function ‘tinytds_err_handler’:
client.c:52: warning: initialization discards qualifiers from pointer target type
client.c: In function ‘tinytds_msg_handler’:
client.c:100: warning: initialization discards qualifiers from pointer target type
/usr/bin/gcc -I. -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1 -I. -DHAVE_ICONV_OPEN -DHAVE_SYBFRONT_H -DHAVE_SYBDB_H -I/opt/homebrew/include -I/usr/local/include -I/usr/include -I'/home/deployer/.rbenv/versions/1.9.2-p290/include' -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -o result.o -c result.c
/usr/bin/gcc -I. -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/deployer/.rbenv/versions/1.9.2-p290/include/ruby-1.9.1 -I. -DHAVE_ICONV_OPEN -DHAVE_SYBFRONT_H -DHAVE_SYBDB_H -I/opt/homebrew/include -I/usr/local/include -I/usr/include -I'/home/deployer/.rbenv/versions/1.9.2-p290/include' -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -o tiny_tds_ext.o -c tiny_tds_ext.c
/usr/bin/gcc -shared -o tiny_tds.so client.o result.o tiny_tds_ext.o -L. -L/home/deployer/.rbenv/versions/1.9.2-p290/lib -Wl,-R/home/deployer/.rbenv/versions/1.9.2-p290/lib -L/home/deployer/.rbenv/versions/1.9.2-p290/lib -Wl,-R/home/deployer/.rbenv/versions/1.9.2-p290/lib -L/opt/homebrew/lib -Wl,-R/opt/homebrew/lib -L/usr/lib -Wl,-R/usr/lib -L. -L'/home/deployer/.rbenv/versions/1.9.2-p290/lib' -rdynamic -Wl,-export-dynamic -lct -lsybdb -lpthread -lrt -ldl -lcrypt -lm -lc
/usr/bin/ld: /opt/homebrew/lib/libsybdb.a(dblib.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/opt/homebrew/lib/libsybdb.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [tiny_tds.so] Error 1
Gem files will remain installed in /home/deployer/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tiny_tds-0.5.1 for inspection.
Results logged to /home/deployer/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/tiny_tds-0.5.1/ext/tiny_tds/gem_make.out
An error occured while installing tiny_tds (0.5.1), and Bundler cannot continue.
Make sure that `gem install tiny_tds -v '0.5.1'` succeeds before bundling.'
Install FreeTDS with homebrew: brew install freetds.
Then, this installation should work: gem install tiny_tds
I run fedora, but the fix for me is
sudo yum install freetds-devel
I am pretty sure that you just need to have the development package of freetds for this to work. After I had the devel package, my
gem install tiny_tds
worked perfectly.
Installing tiny_tds on the Mac:
Installing the tiny_tds gem with bundler requires that FreeTDS be installed first, and also that bundler be told where FreeTDS is located.
First, install FreeTDS:
brew install freetds
By default, tiny_tds will look in certain locations, but freetds, as installed by homebrew, will not be found in any of them:
looking for freetds headers in the following directories:
- /opt/local/include
- /opt/local/include/freetds
- /usr/local/include
- /usr/local/include/freetds
looking for freetds library in the following directories:
- /opt/local/lib
- /opt/local/lib/freetds
- /usr/local/lib
- /usr/local/lib/freetds
So, first you need to find exactly where the freetds lib and include directories are:
ls -l /opt/homebrew/Cellar/freetds
At the time this is posted, the version of freetds installed by brew is 1.3.3, so that is the directory shown by that ls -l:
drwxr-xr-x 15 [username] admin 480 Dec 7 15:36 1.3.3
Then, cd into that folder to see its contents:
cd /opt/homebrew/Cellar/freetds/1.3.3
ls -l
You will find the include and lib directories for freetds in that folder.
Then, tell bundler to tell tiny_tds where to find them:
bundle config set --global build.tiny_tds --with-freetds-dir=/opt/homebrew/Cellar/freetds/1.3.3
Now, you can bundle and the tiny_tds gem will be built.
I got same problem, I solved it with these two commands:
brew install freetds
And you need to install gem with x64 flag:
ARCHFLAGS="-arch x86_64" gem install tiny_tds

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

Installing mechanize gem on Mac OS X 10.4.11 gives 'Failed to build gem native extension'

I'm trying to install mechanize gem on a MAC OS X but I keep getting the following error :
ERROR: Error installing mechanize:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb install mechanize
checking for #include
... yes
checking for #include
... yes
checking for #include
... yes
checking for #include
... yes
checking for xmlParseDoc() in -lxml2... yes
checking for xsltParseStylesheetDoc() in -lxslt... yes
checking for exsltFuncRegister() in -lexslt... yes
creating Makefile
** make
gcc -I. -I. -I/usr/local/lib/ruby/1.8/i686-darwin8.9.1 -I. -I/opt/local/include/ -I/opt/local/include/libxml2 -fno-common -g -O2 -pipe -fno-common -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -c html_document.c
In file included from ./html_document.h:4,
from html_document.c:1:
./native.h:11:28: error: libxml/xmlsave.h: No such file or directory
make: * ** [html_document.o] Error 1**
So xmlsave.h could not be found inside /opt/local/include/ or /opt/local/include/libxml2
The thing is libxml2 is installed as a framework at /Library/Frameworks/libxml2.framework/
Then I decided to create a symlink from libxml headers directory to /opt/local/include/xml2 so I did
ln -s /Library/Frameworks/libxml2.framework/Headers/libxml/ libxml2
but I still can't install the gem.
Any pointers or ideas are very much appreciated.
I ran into this same issue, not installing mechanize but webrat. Here's what worked for me:
sudo ln -s /usr/include/libxml2 /opt/local/include/libxml2

Resources