13

I recently uninstalled Xcode 4.2 and re-installed Xcode 4.3.1. Installed Command Line Tools also. The error says 'C compiler doesn't work`. On searching for this error, it said that it happens when Xcode is not installed. What am I missing?

rvm install 1.9.3 --with-gcc=clang
Installing Ruby from source to: /Users/ava/.rvm/rubies/ruby-1.9.3-preview1, this may take a while depending on your cpu(s)...

ruby-1.9.3-preview1 - #fetching 
ruby-1.9.3-preview1 - #extracting ruby-1.9.3-preview1 to /Users/ava/.rvm/src/ruby-1.9.3-preview1
ruby-1.9.3-preview1 - #extracted to /Users/ava/.rvm/src/ruby-1.9.3-preview1
Fetching yaml-0.1.4.tar.gz to /Users/ava/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /Users/ava/.rvm/src
Configuring yaml in /Users/ava/.rvm/src/yaml-0.1.4.
ERROR: Error running ' ./configure --prefix="/Users/ava/.rvm/usr"  --with-gcc=clang           --build=x86_64-apple-darwin11.3.0           --host=x86_64-apple-darwin11.3.0           --build=x86_64-apple-darwin11.3.0           --host=x86_64-apple-darwin11.3.0 ', please read /Users/ava/.rvm/log/ruby-1.9.3-preview1/yaml/configure.log
Compiling yaml in /Users/ava/.rvm/src/yaml-0.1.4.
ERROR: Error running '/usr/bin/make ', please read /Users/ava/.rvm/log/ruby-1.9.3-preview1/yaml/make.log
Installing yaml to /Users/ava/.rvm/usr
ERROR: Error running '/usr/bin/make install', please read /Users/ava/.rvm/log/ruby-1.9.3-preview1/yaml/make.install.log
ruby-1.9.3-preview1 - #configuring 
ERROR: Error running ' ./configure --prefix=/Users/ava/.rvm/rubies/ruby-1.9.3-preview1 --enable-shared --disable-install-doc  --with-gcc=clang           --build=x86_64-apple-darwin11.3.0           --host=x86_64-apple-darwin11.3.0           --build=x86_64-apple-darwin11.3.0           --host=x86_64-apple-darwin11.3.0 --with-libyaml-dir=/Users/ava/.rvm/usr ', please read /Users/ava/.rvm/log/ruby-1.9.3-preview1/configure.log
ERROR: There has been an error while running configure. Halting the installation.


➜  yaml git:(master) ✗ vi configure.log 

[2012-03-18 21:03:00]  ./configure --prefix="/Users/ava/.rvm/usr"  --with-gcc=clang           --build=x86_64-apple-darwin11.3.0           --host=x86_64-apple-darwin11.3.0           --build=x86_64-apple-darwin11.3.0           --host=x86_64-apple-darwin11.3.0
configure: WARNING: unrecognized options: --with-gcc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... config/install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for x86_64-apple-darwin11.3.0-gcc... no
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/Users/ava/.rvm/src/yaml-0.1.4':
configure: error: C compiler cannot create executables
See `config.log' for more details


➜  ~ git:(master) ✗ gcc -v   
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.9~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)


➜  ~ git:(master) ✗ which gcc
/usr/bin/gcc
Ava
  • 5,783
  • 27
  • 58
  • 86
  • Can you simply pass `CC=clang` as an environment variable on the command line to `configure` or whatever invokes it? – Brett Hale Mar 19 '12 at 11:07
  • you mean like this on Terminal? `➜ ~ git:(master) ✗ CC=clang ➜ ~ git:(master) ✗ ` – Ava Mar 19 '12 at 12:42

7 Answers7

23

In the Terminal:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Also, in Xcode, make sure the Command Line Tools are installed. Choose Xcode > Preferences, click on Downloads, and if necessary, click the Install button next to "Command Line Tools".

Kurt Revis
  • 27,695
  • 5
  • 68
  • 74
  • `➜ ~ git:(master) ✗ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer Password: ➜ ~ git:(master) ✗ ` Nothing happens. – Ava Mar 19 '12 at 05:09
  • `xcode-select` doesn't print anything, true, but does the build work after you did it? You didn't say whether you tried again. – Kurt Revis Mar 19 '12 at 05:16
  • This article helped me out: http://stackoverflow.com/a/13595772/1008519 It creates a symbolic link so the compiler is able to find the toolchain – mlunoe Jul 09 '13 at 08:39
  • Worked for me. I had a developer preview and another version isntalled. – Ahmed Abbas Sep 17 '14 at 20:11
7
  1. you use old RVM which does not know about latest ruby pathclevel, update with rvm get head

  2. Ruby is not yet fully ready for LLVM, your get best chances for compilation using osx-gcc-installer and --with-gcc=gcc-4.2

mpapis
  • 52,729
  • 14
  • 121
  • 158
  • 1
    Ruby 1.9.3 can be compiled with clang. – mipadi Mar 19 '12 at 15:19
  • 2
    yes but only 1.9.3-p125 and it still has issues, I heard that 1.9.3-head is better - but still not everything – mpapis Mar 19 '12 at 15:46
  • 1
    I managed to install `ruby-1.9.3 p484` with `gcc-4.9` with following command: `rvm install ruby-1.9.3-p484 --with-gcc=gcc-4.9` Thanks for sharing this comment; it was useful! – Oto Brglez Oct 15 '14 at 12:14
  • +1 for `rvm install ruby-1.9.3-p484 --with-gcc=gcc-4.9` for resolving the `checking whether the C compiler works... no` problem. – RainChen Jan 31 '15 at 05:53
5

I fixed it by running :

rvm install <ruby-version> --with-gcc=clang

Replace < ruby-version> with version you want to use

7Vals
  • 51
  • 1
  • 1
2

For those out there running into the same problem,

System (in order of installation)

I had set LDFLAGS and CPPFLAGS to point to Homebrew installations, this resulted in errors. I "unlinked" LDFLAGS and CPPFLAGS, ran 'rvm install 1.9.2' and everything worked fine.

  • rvm install 1.9.2
westonplatter
  • 1,475
  • 2
  • 19
  • 30
0

Try ./configure --without-gcc to use clang.

Sreejith Ramakrishnan
  • 1,332
  • 2
  • 13
  • 22
0

I'm on Mavericks and the provided answers didn't work for me. However, updating my version of Xcode and making sure Command Line Tools are installed did the trick.

DemitryT
  • 391
  • 4
  • 17
0

It is a lot easier to install by using the compiler the system knows about

1. rvm install ruby-1.9.3-p547 --with-gcc=`echo which gcc`
Jones Agyemang
  • 1,230
  • 16
  • 15