Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

ruby on rails - The compiler failed to generate an executable file. (RuntimeError)

I recently upgraded to OS Mountain Lion. A project I'm working on requires gem sys-proctable as a dependency, but when I run bundle install I get:

Fetching gem metadata from https://rubygems.org/.........
.
.
.
Installing sys-proctable (0.9.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for rb_pid_t in ruby.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `block in try_compile'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:443:in `with_werror'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `try_compile'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1022:in `try_type'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1050:in `block in have_type'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1049:in `have_type'
    from extconf.rb:3:in `<main>'


Gem files will remain installed in /Users/mgriffel/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/sys-proctable-0.9.2-universal-darwin for inspection.
Results logged to /Users/mgriffel/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/sys-proctable-0.9.2-universal-darwin/ext/darwin/gem_make.out
An error occurred while installing sys-proctable (0.9.2), and Bundler cannot continue.
Make sure that `gem install sys-proctable -v '0.9.2'` succeeds before bundling.

But I do have developer tools installed! Running gem install sys-proctable -v '0.9.2' gives me nearly the same error:

Building native extensions.  This could take a while...
ERROR:  Error installing sys-proctable:
    ERROR: Failed to build gem native extension.

        /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_pid_t in ruby.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `block in try_compile'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:443:in `with_werror'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `try_compile'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1022:in `try_type'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1050:in `block in have_type'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1049:in `have_type'
    from extconf.rb:3:in `<main>'


Gem files will remain installed in /Users/mgriffel/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/sys-proctable-0.9.2-universal-darwin for inspection.
Results logged to /Users/mgriffel/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/sys-proctable-0.9.2-universal-darwin/ext/darwin/gem_make.out
[sample_app(filling-in-layout)]$ /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
                                                                              A [sample_app(filling-in-layout)]$ gem install sys-proctable -v '0.9.2'
Building native extensions.  This could take a while...
ERROR:  Error installing sys-proctable:
    ERROR: Failed to build gem native extension.

        /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_pid_t in ruby.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `block in try_compile'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:443:in `with_werror'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `try_compile'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1022:in `try_type'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1050:in `block in have_type'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:1049:in `have_type'
    from extconf.rb:3:in `<main>'


Gem files will remain installed in /Users/mgriffel/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/sys-proctable-0.9.2-universal-darwin for inspection.
Results logged to /Users/mgriffel/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/sys-proctable-0.9.2-universal-darwin/ext/darwin/gem_make.out

Here's the content of my mkmf.log file:

"/usr/bin/gcc-4.2 -o conftest -I/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -I/Users/mgriffel/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/opt/sm/pkg/active/include -fno-common -pipe conftest.c  -L. -L/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194/lib -L/Users/mgriffel/.rvm/usr/lib -L. -L/opt/sm/pkg/active/lib -L/usr/local/lib     -lruby.1.9.1  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

Now I recently reinstalled XCode and Command Line Tools, but I'm worried that I somehow fucked up my C compiler, because when I try to run rvm --force install 1.9.3 I get the following errors:

No binary rubies available for: downloads/ruby-1.9.3-p194.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
lipo: can't open input file:  (No such file or directory)
Fetching yaml-0.1.4.tar.gz to /Users/mgriffel/.rvm/archives
Extracting yaml to /Users/mgriffel/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/mgriffel/.rvm/src/yaml-0.1.4.
Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure --prefix=/Users/mgriffel/.rvm/usr', please read /Users/mgriffel/.rvm/log/ruby-1.9.3-p194/yaml/configure.log
Compiling yaml in /Users/mgriffel/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/mgriffel/.rvm/usr
Installing Ruby from source to: /Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194, this may take a while depending on your cpu(s)...
ruby-1.9.3-p194 - #downloading ruby-1.9.3-p194, this may take a while depending on your connection...
ruby-1.9.3-p194 - #extracted to /Users/mgriffel/.rvm/src/ruby-1.9.3-p194 (already extracted)
Patch cflags was already applied.
ruby-1.9.3-p194 - #configuring
Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include -L/Users/mgriffel/.rvm/usr/lib ./configure --enable-shared --disable-install-doc --prefix=/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194 --with-gcc=clang', please read /Users/mgriffel/.rvm/log/ruby-1.9.3-p194/configure.log
There has been an error while running configure. Halting the installation.

Contents of configure.log

[2012-11-07 18:02:12] env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include -L/Users/mgriffel/.rvm/usr/lib ./configure --enable-shared --disable-install-doc --prefix=/Users/mgriffel/.rvm/rubies/ruby-1.9.3-p194 --with-gcc=clang
checking build system type... x86_64-apple-darwin12.2.0
checking host system type... x86_64-apple-darwin12.2.0
checking target system type... x86_64-apple-darwin12.2.0
checking whether the C compiler works... no
configure: error: in `/Users/mgriffel/.rvm/src/ruby-1.9.3-p194':
configure: error: C compiler cannot create exec

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Same problem occurred and I finally solved it. Here are the steps I followed:

  • Xcode, Xcode CLT
  • sudo xcodebuild -license
  • sudo port upgrade outdated
  • sudo port install apple-gcc42
  • rvm reinstall 1.9.3 #important!

Really, I think just first,second and last steps required, but can not test it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...