Cannot compile ruby 1.9.3

10,538

Solution 1

you are using clang, according to this ticket http://bugs.ruby-lang.org/issues/5883 - it's not "fully" supported - you need to try using gcc-4.2, you get instructions for homebrew with running rvm requirements.

here is RVM ticket for this problem https://github.com/wayneeseguin/rvm/issues/1480

UPDATE: Ruby-2.0.0 actually compiles better with clang then with gcc-4.2, more details here: https://stackoverflow.com/a/15655034/497756

Solution 2

With Xcode 4.6 I was also getting this problem. I installed the command line tools which made gcc available in /usr/bin/gcc.

I managed to get it to work using:

rvm install 1.9.3 --with-gcc=gcc

NB. I dont have homebrew installed.

Solution 3

If you don't have rvm already installed, rvm requirements won't work. Install gcc 4.2 with homebrew and restart the rvm installation. Worked for me.

brew update
brew tap homebrew/dupes
brew install apple-gcc42

Solution 4

If you are using rbenv and ruby-build instead of rvm, you have to define, which compiler should be used to build ruby:

# this export must be done before every new ruby build
export CC=gcc
# use the version you wish to install
rbenv install 1.9.3-p385

If it doesn't work, you need to install Gnu C Compiler (gcc) first:

brew update
brew tap homebrew/dupes
# install gcc, only once needed
brew install gcc
# You can view the installed GCC version, currently gcc-8
brew info gcc
# Maybe you have to tell, which gcc version must be used,
# to get it working.
export CC=gcc-8

For older Systems or not up to date systems install old GCC 4.2 version:

brew update
brew tap homebrew/dupes
# install apple-gcc, only once needed
brew install apple-gcc42
# Maybe you have to tell, which gcc version must be used,
# to get it working on newer systems
export CC=gcc-4.2

Until the ruby folks build a clang compatible ruby version, you have to export the CC variable before every build of a new ruby version or simply add the export to your .bashrc oder .zshenv file.

Solution 5

I solved this using Macports.

I had problems compiling and were getting the error "Ruby 'ruby-1.9.3-p374' was built using clang - but it's not (fully) supported, expect errors."

Github was also down for maintenance so I couldnt try compiling using brew as suggested in the previous answer... This is what I did, and it compiled fine on Mountain Lion 10.8.2:

First install Macports

http://www.macports.org/install.php

Then run:

sudo port selfupdate

sudo port install apple-gcc42

sudo rvm install ruby-1.9.3-p374 --with-gcc=gcc-apple-4.2

Share:
10,538

Related videos on Youtube

Will
Author by

Will

Updated on June 04, 2022

Comments

  • Will
    Will about 2 years

    When I run

    rvm install 1.9.3 --with-gcc=clang
    

    on Mac OSX Lion, ruby does not compile, and I get the following error in (.rvm/log/ruby-1.9.3-p374/make.log)

    [2013-01-29 16:31:05] make
    CC = clang
    LD = ld
    LDSHARED = clang -dynamic -bundle
    CFLAGS = -O3 -ggdb -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration  -pipe 
    XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT
    CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/Users/will/.rvm/usr/include -I. -I.ext/include/x86_64-darwin12.2.1 -I./include -I.
    DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace  
    SOLIBS = 
    compiling regparse.c
    regparse.c:582:15: error: implicit conversion loses integer precision: 'st_index_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
    return t->num_entries;
    ~~~~~~ ~~~^~~~~~~~~~~
    1 error generated.
    make: *** [regparse.o] Error 1
    

    How can I get ruby 1.9.3 to install on Lion?

    • Preston Lee
      Preston Lee over 11 years
      I have the same issue on Mountain Lion with 1.9.3-p374. I upgraded to Xcode 4.6 yesterday and am installing p374 via rvm .. curious if it's related to Xcode tools?
  • Will
    Will over 11 years
    This compiled, but ended up using clang and crashed with errors when executed.
  • Siddhartha
    Siddhartha over 11 years
    I am facing same issues while installing rvm on Mac, I am using following command to install rvm on Mac, "$ \curl -L get.rvm.io | bash -s stable --ruby". Is there any alternate way to install rvm using gcc?
  • mpapis
    mpapis over 11 years
    Siddhart skip the --ruby flag and make sure to read rvm requirements before you install ruby: rvm install 1.9.3.
  • Peter DeWeese
    Peter DeWeese over 11 years
    Although it returns the error Ruby 'ruby-1.9.3-p374' was built using clang - but it's not (fully) supported, expect errors., it seems to work.
  • fearless_fool
    fearless_fool over 11 years
    @mpapis: can you expand on the comment "Ruby-2.0.0 actually compiles better with clang then with gcc-4.2"? I'm having trouble compiling Ruby 2.0 under gcc-4.2 -- see gist.github.com/rdpoor/5249186 -- is this what you're describing (and are there any resolutions)?
  • mpapis
    mpapis over 11 years
    yes this is exactly that problem, see this: stackoverflow.com/a/15655034/497756
  • Gon Zifroni
    Gon Zifroni over 10 years
    On an OSX box this is the command you need to run rvm install ruby-1.9.3-p194 --with-gcc=/usr/bin/gcc-4.2.
  • mpapis
    mpapis about 10 years
    this works only on older OSX where there was /usr/bin/gcc-4.2
  • Rick Fletcher
    Rick Fletcher almost 7 years
    This didn't quite work for me even with apple-gcc42 installed. Turned out that my gcc command was actually clang, and I had to use export CC=gcc-4.2 to get the real thing.
  • d_rail
    d_rail almost 6 years
    Update: brew install gcc export CC=gcc-8