简体   繁体   中英

Can't compile ruby extensions: CPU you selected does not support x86-64 instruction set

I can't compile ruby extensions using RVM and ruby 2.3.0 (2.2.1 is the same), with message: city.cc:1:0: error: CPU you selected does not support x86-64 instruction set I'm using x86_64 Debian Wheezy, x86_64 ruby and gcc, on a 64bit CPU. Despite that, seems that ruby uses -march=native which generates the problem. I cannot figure out how to fix this.

Details below:

Compiling an example extension:

gem install cityhash
Building native extensions.  This could take a while...
ERROR:  Error installing cityhash:
    ERROR: Failed to build gem native extension.

current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/cityhash-0.8.1/ext/cityhash
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r  ./siteconf20160317-15208-1shn16g.rb extconf.rb
creating Makefile

current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/cityhash-0.8.1/ext/cityhash
make "DESTDIR=" clean

current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/cityhash-0.8.1/ext/cityhash
make "DESTDIR="
compiling city.cc
cc1plus: warning: command line option ‘-Wdeclaration-after-statement’ is valid for C/ObjC but not for C++ [enabled by default]
cc1plus: warning: command line option ‘-Wimplicit-function-declaration’ is valid for C/ObjC but not for C++ [enabled by default]
city.cc:1:0: error: CPU you selected does not support x86-64 instruction set
make: *** [city.o] Błąd 1

make failed, exit code 2

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.0/gems/cityhash-0.8.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/cityhash-0.8.1/gem_make.out

The makefile is trying to run these commands:

$ make -n
echo compiling city.cc
g++ -I. -I/usr/local/rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/x86_64-linux -I/usr/local/rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/backward -I/usr/local/rvm/rubies/ruby-2.3.0/include/ruby-2.3.0 -I.   -g -O3 -Wall -march=native -fPIC -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat  -o city.o -c city.cc
echo compiling cityhash.cc
g++ -I. -I/usr/local/rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/x86_64-linux -I/usr/local/rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/backward -I/usr/local/rvm/rubies/ruby-2.3.0/include/ruby-2.3.0 -I.   -g -O3 -Wall -march=native -fPIC -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat  -o cityhash.o -c cityhash.cc
echo linking shared-object cityhash/cityhash.so 
rm -f cityhash.so
g++ -shared -o cityhash.so city.o cityhash.o -L. -L/usr/local/rvm/rubies/ruby-2.3.0/lib -Wl,-R/usr/local/rvm/rubies/ruby-2.3.0/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic    -Wl,-R/usr/local/rvm/rubies/ruby-2.3.0/lib -L/usr/local/rvm/rubies/ruby-2.3.0/lib -lruby  -lpthread -lrt -ldl -lcrypt -lm   -lc

uname, ruby, gcc versions -- all seem to be 64bit:

$ uname -a
Linux bukwica-prod 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u6 x86_64 GNU/Linux
$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5) 

..although I don't know why for -match=native I get pentium-m

$ gcc -march=native -Q --help=target |grep march
-march=                             pentium-m

I'm out of ideas, please help!

It's being set explicitly in the gem (incorrectly)

%w{g O3 Wall march=native}.each do |flag|
  flag = "-#{flag}"
  $CPPFLAGS += " #{flag}" unless $CPPFLAGS.split.include? flag
end

Should be:

%w{g O3 Wall march}.each do |flag|
  flag = "-#{flag}"
  $CPPFLAGS += " #{flag}" unless $CPPFLAGS.split.include? flag
end

This pull request updates to remove march completely, but it's really old so don't count on anything changing there.

You can override where bundle pulls the gem from by putting this in your Gemfile :

gem 'cityhash', :git => 'git://github.com/lyfeyaj/cityhash.git'

That will install the forked version that contains the pull request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM