zima
zima

Reputation: 743

rails 4 gem install error using homebrew-installed gcc compiler

I am installing gem sqlite3 for rails 4 and get a compilation error. This is a completely new macbook pro with Mavericks OS installed. I have installed XCode, but then also installed gcc 4.9 using Homebrew (using instructions here). Everything was going smooth until I started getting a compilation error while trying to install the gem sqlite3:

    app_folder git:(mybranch) gem install sqlite3 -v '1.3.8'
    Building native extensions.  This could take a while...
    ERROR:  Error installing sqlite3:
ERROR: Failed to build gem native extension.

    /Users/myname/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb
    checking for sqlite3.h... yes
    checking for sqlite3_libversion_number() in -lsqlite3... yes
    checking for rb_proc_arity()... yes
    checking for sqlite3_initialize()... yes
    checking for sqlite3_backup_init()... yes
    checking for sqlite3_column_database_name()... no
    checking for sqlite3_enable_load_extension()... no
    checking for sqlite3_load_extension()... no
    checking for sqlite3_open_v2()... yes
    checking for sqlite3_prepare_v2()... yes
    checking for sqlite3_int64 in sqlite3.h... yes
    checking for sqlite3_uint64 in sqlite3.h... yes
    creating Makefile

    make "DESTDIR="
    compiling backup.c
    gcc-4.9: error: unrecognized command line option '-Wshorten-64-to-32'
    make: *** [backup.o] Error 1

Upon doing some research of the issue, I have found little information besides that this command line option is mac-specific and Homebrew-installed gcc compiler does not have it! Is there a way for me to switch back to native mac gcc compiler? How do I resolve this and why is it barely mentioned anywhere?

    gcc -v
    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-       include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
    Target: x86_64-apple-darwin13.0.1

Upvotes: 2

Views: 1398

Answers (1)

Michael Asnes
Michael Asnes

Reputation: 83

I just installed Rails and had a similar experience. I fixed it by getting osx to recognize the correct g++ version and then reinstalling ruby. Here are a few suggestions:

  1. You can set your gcc and g++ version via .bash_profile with the following code

    export CC=gcc-4.9
    export CXX=g++-4.9
    export CPP=cpp-4.9
    

    check your g++ version with g++ -v. If this doesn't work you may need to do bit of hacking.

  2. Per http://instantbadger.blogspot.com/2011/11/porting-rails-23-app-to-ruby-19.html, you can remove the default g++ in /usr/bin and substitute it with a new symlink to g++-4.9:

    sudo mv /usr/bin/g++ /usr/bin/g++.bak && sudo ln -s /usr/local/bin/g++-4.9 /usr/bin/g++
    

    Note: this command is different from the one present in the linked page (which moves /usr/local/bin/g++). I didn't have a copy of g++ in /usr/local/bin/, so I adapted the command to work with /usr/bin instead.

    Check g++ -v again. It should now reflect the correct version of g++.

Once your g++ version checks out, you can try reinstalling ruby. This insures that your ruby version is compiled with the same compiler that your going to build your gems with.

    rvm install 2.0.0

Once you've done that, repeat

    gem install sqlite3 -v '1.3.8'

Hopefully, this should work now.

Upvotes: 3

Related Questions