SciRuby/nmatrix

Update extconf.rb so Mac OS X always uses clang (if correct version is available) and stops looking for GCC

xMinh129 opened this issue · 15 comments

I'm having this issue while trying to install a gem. Anybody could help me? Appreciate it a lot!

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/minhvu/.rvm/gems/ruby-2.3.0/gems/bindex-0.5.0/ext/bindex
/Users/minhvu/.rvm/rubies/ruby-2.3.0/bin/ruby -r
./siteconf20170507-3967-bvkwf8.rb extconf.rb
creating Makefile

current directory:
/Users/minhvu/.rvm/gems/ruby-2.3.0/gems/bindex-0.5.0/ext/bindex
make "DESTDIR=" clean

current directory:
/Users/minhvu/.rvm/gems/ruby-2.3.0/gems/bindex-0.5.0/ext/bindex
make "DESTDIR="
compiling cruby.c
gcc: error: unrecognized command line option ‘-Wshorten-64-to-32’
gcc: error: unrecognized command line option ‘-Wdivision-by-zero’; did you mean
‘-Wdiv-by-zero’?
gcc: error: unrecognized command line option ‘-Wextra-tokens’; did you mean
‘--extra-warnings’?
make: *** [cruby.o] Error 1

make failed, exit code 2

Gem files will remain installed in
/Users/minhvu/.rvm/gems/ruby-2.3.0/gems/bindex-0.5.0 for inspection.
Results logged to
/Users/minhvu/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-16/2.3.0/bindex-0.5.0/gem_make.out

An error occurred while installing bindex (0.5.0), and Bundler cannot
continue.
Make sure that `gem install bindex -v '0.5.0'` succeeds before bundling.

This is my ruby version : ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin16]

v0dro commented

If you're on Mac you should clang not gcc. #584

@v0dro We should probably fix this. The weird stuff in extconf is a workaround for when clang wasn't able to compile NMatrix and we had to use GCC. Now the reverse is true, and GCC won't work, but clang does.

v0dro commented

Yes you have a point. I don't have access to a Mac though so I can't work on this as of now.

I think it should be a small change in extconf which will first check the environment and set the variables in CONFIG appropriately.

See this: http://stackoverflow.com/questions/4554837/how-to-specify-compiler-for-gem-install

Or maybe use use rake-compiler.

We don't need to rewrite extconf totally. It's already overriding the system default to use GCC on Mac. We just need to remove the override.

If you're on Mac you should clang not gcc. #584

how exactly? don't assume i have any idea what i'm doing.

if someone's at least willing to help me understand the problem, i'd be happy to try and work out a solution.

worked around by temporarily symlinking to clang.

mv /usr/local/bin/gcc-4.9 /usr/local/bin/gcc-4.9-orig
mv /usr/local/bin/g++-4.9 /usr/local/bin/g++-4.9-orig
ln -s $(which clang) /usr/local/bin/gcc-4.9
ln -s $(which clang++) /usr/local/bin/g++-4.9
gem install nmatrix
rm /usr/local/bin/gcc-4.9 /usr/local/bin/g++-4.9
mv /usr/local/bin/gcc-4.9-orig /usr/local/bin/gcc-4.9
mv /usr/local/bin/g++-4.9-orig /usr/local/bin/g++-4.9
lonny commented

I am having this issue, too. Or one that is closely related. The error is:

mkmf.rb:50:in 'gplusplus_version': unable to determine g++ version (match to get version was nil) (RuntimeError)
extconf failed, exit code 1

This occurred both before and after I followed the instructions for OS X here: https://github.com/SciRuby/nmatrix/wiki/Installation

I also tried setting up a symbolic ink for g++-4.8, to match the one for gcc. When I did that, I got a different error, as shown in the mkmf.log file

gcc: error: unrecognized command line option '-Wshorten-64-to-32'
gcc: error: unrecognized command line option '-Wdivision-by-zero'
gcc: error: unrecognized command line option '-Wextra-tokens'
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

This is a big problem. mikecmpbll's fix didn't work for me, either, as I am now on OS X 10.10.5.

I should also note: this is a local problem. I did manage to get nmatrix installed on our Linux server. But once I did, every time we run a script we get the following message, repeated 8 times, whenever a script starts up (even scripts that do not use nmatrix):

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from require at /home/deploy/.gem/ruby/2.3.0/gems/bundler-1.16.0/lib/bundler/runtime.rb:81)

That is on Ruby 2.3.3p222, Rails 5.0.0.1.

Okay. So, it now appears that in High Sierra, the default is clang. You can check this by doing

require 'mkmf'
puts CONFIG['CC']

If that's not the case for you, please let me know.

@lonny, I believe your issue is now resolved in #601.

lonny commented

@MohawkJohn Only if I can successfully upgrade to High Sierra. So far, it has been no go.

@lonny You should still be able to compile with clang/clang++. What happens if you open irb and do the thing I suggested above?

lonny commented

2.3.0 :002 > puts CONFIG['CC']
gcc
=> nil

lonny commented

I am going to continue my efforts to upgrade to High Sierra. But I have to do that on my "off time", as it were.

What about if you do CC=clang CXX=clang++ bundle exec rake compile?

lonny commented

<path>/mkmf.rb:50:in 'gplusplus_version': unable to determine g++ version (match to get version was nil) (RuntimeError)
from /Users/lonny/.rvm/gems/ruby-2.3.0@ey/gems/nmatrix-0.2.3/lib/nmatrix/mkmf.rb:71:in '<top (required)>'
from extconf.rb:28:in 'require'
from extconf.rb:28:in '<main>'

lonny commented

Just as a followup:

I checked the config for my ruby as in the description here:

https://stackoverflow.com/questions/4554837/how-to-specify-compiler-for-gem-install

and it is already set to use clang and clang++. When I type "which gcc" I get usr/bin/gcc/. When I type
gcc --version
it definitely says clang. Both in Yosemite (10.10.5) and El Capitan (10.11).