configure: error: C compiler cannot create executables

I have 10.8 installed and Xcode 4.4 with Command Line tools, and yet I was still getting this error. Rather than reinstall Xcode, I noticed there were two relevant lines in my config.log:

configure:5130: checking for C compiler version
configure:5139: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc --version >&5

That path did not exist for me. Instead I had:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain

The C compiler ("cc") is located inside of that xctoolchain directory. I created a symlink for OSX10.8.xctoolchain to point to XcodeDefault.xctoolchain and that fixed it. Now the memcached installation script can find the compiler version and continue on its way.

cd /Applications/Xcode.app/Contents/Developer/Toolchains
sudo ln -s XcodeDefault.xctoolchain OSX10.8.xctoolchain

As suggested in the comments, if you are having this problem on Yosemite (10.10) or Mavericks (10.9), you can update the symlink command above to point to that specific version (OSX10.9.xctoolchain or OSX10.10.xctoolchain).


You have an old set of developer tools. gcc is reporting its version as 4.0.1. This may be left over from migrating from an older version of the OS. If you've installed Xcode 4.3.x, you need to launch it, go into its preferences, select the Locations tab, and click "Install" next to the Command Line Tools package.