21

Trying to install thift gem after OSX El Capitan upgrade:

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

        /Users/foo/.rvm/rubies/ruby-2.1.4/bin/ruby -r ./siteconf20160402-32256-7dzqel.rb extconf.rb
    checking for strlcpy() in string.h... yes
    creating Makefile

    make "DESTDIR=" clean

    make "DESTDIR="
    compiling binary_protocol_accelerated.c
    compiling bytes.c
    compiling compact_protocol.c
    compact_protocol.c:442:41: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
        rb_exc_raise(get_protocol_exception(INT2FIX(-1), rb_str_new2(buf)));
                                            ^~~~~~~~~~~

Compilation fails with compact_protocol.c:442:41: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]

Matt
  • 74,352
  • 26
  • 153
  • 180
Anton
  • 905
  • 8
  • 18
  • Did you accept the new Xcode EULA? – Todd A. Jacobs Apr 02 '16 at 21:08
  • @CodeGnome yes I did – Anton Apr 03 '16 at 01:27
  • 3
    What is your gcc version? Try using gcc 4.x. E.g. `brew install gcc49`, `ln -s /usr/local/bin/gcc-49 /usr/local/bin/gcc`. Make sure `gcc --version` returns the GNU compiler, not Apple LLVM and then install the gem: `gem install thrift`. – Michał Knapik Apr 04 '16 at 12:51
  • 2
    this is not a duplicate, I have the same error and I belive it relates to the description of the bug here: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=202660. Basically an issue with ruby.h on ruby versions < 2.2 and the new gcc on elcapitan – giladbu Apr 07 '16 at 06:23
  • 1
    @Anton: Now that I have reopened the question, please post your solution/ update as a fleshed out answer, rather than appending it to the question – Matt Apr 08 '16 at 17:14
  • 1
    @MichałKnapik thank you for the suggestion but that didn't work for me on El Capitan 10.11.4. – dmarwick Apr 08 '16 at 20:11

5 Answers5

63

I have a solution for you! Hopefully.

Had this same problem the other day.

The problem is in the clang compiler that El Capitan comes bundled with. I'm sure it screws up other issues but this is one point that I had a lot of issues with.

Try running the following command and let me know how it goes!

gem install thrift -- --with-cppflags=\"-D_FORTIFY_SOURCE=0 -Wno-shift-negative-value\"
nobody
  • 7,803
  • 11
  • 56
  • 91
  • 1
    This method didn't work for me. clang version: `Apple LLVM version 7.3.0 (clang-703.0.29)`, os x version: El Capitan 10.11.4 – Michał Knapik Apr 10 '16 at 17:56
  • Might want to open up a separate question then with a full error output from that command so we can better help you! – nobody Apr 10 '16 at 17:57
  • 2
    This works with gem install, but bundle install is not working. I tried `bundle config build.thrift "--with-cppflags=-D_FORTIFY_SOURCE=0"` but that is not working, any idea on how to solve for -Wno-shift-negative-value option in bundle config? – Kiran A B May 13 '16 at 19:01
20

You need to escape double quotes.

$ bundle config build.thrift "--with-cppflags=\"-D_FORTIFY_SOURCE=0 -Wno-shift-negative-value\""

$ cat ~/.bundle/config

BUNDLE_BUILD__THRIFT: --with-cppflags="-D_FORTIFY_SOURCE=0 -Wno-shift-negative-value"

  • That doesn't work for me: `BUNDLE_BUILD__THRIFT: "--with-cppflags=\"-D_FORTIFY_SOURCE=0 -Wno-shift-negative-value\""` – the_drow Dec 14 '16 at 11:09
  • For jenkins builds, I had to escape the space between the 2 variables: `bundle config build.thrift "--with-cppflags=\"-D_FORTIFY_SOURCE=0\ -Wno-shift-negative-value\""` – hammady Jan 23 '17 at 10:47
9

There is help for Big Sur https://github.com/instructure/canvas-lms/issues/827#issuecomment-946388555

gem install thrift -v 0.15.0 -- --with-cppflags="-Wno-compound-token-split-by-macro"
Dmytro Stekanov
  • 116
  • 1
  • 3
1

This worked for me on mac bigsur

gem install thrift -v '0.10.0.0' -- --with-cppflags="-D_FORTIFY_SOURCE=0 -Wno-shift-negative-value -Wno-compound-token-split-by-macro" 
-1

Try this

gem install thrift -v '0.9.0' -- --with-cppflags='-D_FORTIFY_SOURCE=0'
Ishwar
  • 11
  • 1