无法编译ruby扩展:您选择的CPU不支持x86-64指令集

时间:2016-03-17 14:42:51

标签: ruby gcc 64-bit rvm native

我无法使用RVM和ruby 2.3.0(2.2.1是相同的)编译ruby扩展,并带有消息:     city.cc:1:0:错误:您选择的CPU不支持x86-64指令集 我在64位CPU上使用x86_64 Debian Wheezy,x86_64 ruby​​和gcc。 尽管如此,似乎ruby使用-march=native来产生问题。我无法弄清楚如何解决这个问题。

以下详细信息:

编译示例扩展名:

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

makefile正在尝试运行这些命令:

$ 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版本 - 似乎都是64位:

$ 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) 

..虽然我不知道为什么-match = native我得到了pentium-m

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

我没有想法,请帮助!

1 个答案:

答案 0 :(得分:0)

它是set explicitly in the gem(错误地)

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

应该是:

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

pull request更新完全删除游行,但它已经过时了,所以不要指望那里的任何变化。

您可以通过将bundle放入Gemfile来覆盖gem 'cityhash', :git => 'git://github.com/lyfeyaj/cityhash.git' 拉出宝石的位置:

[{
  type: 'cond',
  conditionId: 1,
  conditions: undefined
},
{
  type: 'cond',
  conditionId: 2,
  conditions: undefined
},
{
  type: 'group',
  conditionId: undefined,
  conditions: [{
      type: 'cond',
      conditionId: 3,
      conditions: undefined
    },
    {
      type: 'cond',
      conditionId: 4,
      conditions: undefined
    }]
}]

这将安装包含拉取请求的分叉版本