configure: error: C compiler cannot create executables

228,212

Solution 1

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.

Solution 2

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).

Solution 3

When you see this error message, you might not have accepted the Xcode license agreement yet after an upgrade.

First of all, make sure you have upgraded your commandline tools:

$ xcode-select --install

Now Apple wants you to agree to their license before you can use these tools:

$ gcc
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

$ sudo gcc
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
[...]

After you have accepted it, the commandline tools will work as expected.

Solution 4

I had already installed the command line tools in xcode but I mine still errored out on:

line 3619: /usr/bin/gcc-4.2: No such file or directory

When I entered which gcc it returned

/usr/bin/gcc

When I entered gcc -v I got a bunch of stuff then

..  
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

So I created a symlink:

cd /usr/bin
sudo ln -s gcc gcc-4.2

And it worked!

(the config.log file is located in the directory that make is trying to build something in)

Solution 5

I just had this issue building apache. The solution I used was the same as Mostafa, I had to export 2 variables:

export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
CPP='/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -E'

This was one Mac OSX Mavericks

Share:
228,212

Related videos on Youtube

CourtDemone
Author by

CourtDemone

Updated on July 08, 2022

Comments

  • CourtDemone
    CourtDemone almost 2 years

    I've checked a number of similar questions on stackoverflow but haven't found an answer yet.

    I'm trying to install memcached on Lion OSX as shown here.

    Here's what I'm getting:

    j-court-demones-macbook-pro:libevent-1.4.12-stable jcourtdemone$ ./configure; make
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for a thread-safe mkdir -p... ./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 gcc... gcc
    checking for C compiler default output file name... 
    configure: error: in `/tmp/libevent-1.4.12-stable':
    configure: error: C compiler cannot create executables
    See `config.log' for more details.
    make: *** No targets specified and no makefile found.  Stop.
    

    I've reinstalled Xcode as was recommended in a couple places, but no dice.

    Here's my config.log:

    This file contains any messages produced by compilers while
    running configure, to aid debugging if configure makes a mistake.
    
    It was created by configure, which was
    generated by GNU Autoconf 2.63.  Invocation command line was
    
      $ ./configure 
    
    ## --------- ##
    ## Platform. ##
    ## --------- ##
    
    hostname = j-court-demones-macbook-pro.local
    uname -m = x86_64
    uname -r = 11.3.0
    uname -s = Darwin
    uname -v = Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64
    
    /usr/bin/uname -p = i386
    /bin/uname -X     = unknown
    
    /bin/arch              = unknown
    /usr/bin/arch -k       = unknown
    /usr/convex/getsysinfo = unknown
    /usr/bin/hostinfo      = Mach kernel version:
         Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64
    Kernel configured for up to 8 processors.
    4 processors are physically available.
    8 processors are logically available.
    Processor type: i486 (Intel 80486)
    Processors active: 0 1 2 3 4 5 6 7
    Primary memory available: 4.00 gigabytes
    Default processor set: 109 tasks, 599 threads, 8 processors
    Load average: 0.98, Mach factor: 7.01
    /bin/machine           = unknown
    /usr/bin/oslevel       = unknown
    /bin/universe          = unknown
    
    PATH: /opt/local/bin
    PATH: /opt/local/sbin
    PATH: /opt/local/bin
    PATH: /opt/local/sbin
    PATH: /usr/bin
    PATH: /Developer/usr/bin
    PATH: /usr/bin
    PATH: /bin
    PATH: /usr/sbin
    PATH: /sbin
    PATH: /usr/local/bin
    PATH: /usr/X11/bin
    
    
    ## ----------- ##
    ## Core tests. ##
    ## ----------- ##
    
    configure:2077: checking for a BSD-compatible install
    configure:2145: result: /usr/bin/install -c
    configure:2156: checking whether build environment is sane
    configure:2199: result: yes
    configure:2224: checking for a thread-safe mkdir -p
    configure:2263: result: ./install-sh -c -d
    configure:2276: checking for gawk
    configure:2306: result: no
    configure:2276: checking for mawk
    configure:2306: result: no
    configure:2276: checking for nawk
    configure:2306: result: no
    configure:2276: checking for awk
    configure:2292: found /usr/bin/awk
    configure:2303: result: awk
    configure:2314: checking whether make sets $(MAKE)
    configure:2336: result: yes
    configure:2575: checking for gcc
    configure:2591: found /Developer/usr/bin/gcc
    configure:2602: result: gcc
    configure:2834: checking for C compiler version
    configure:2842: gcc --version >&5
    i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5484)
    Copyright (C) 2005 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    configure:2846: $? = 0
    configure:2853: gcc -v >&5
    Using built-in specs.
    Target: i686-apple-darwin9
    Configured with: /var/tmp/gcc/gcc-5484~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
    Thread model: posix
    gcc version 4.0.1 (Apple Inc. build 5484)
    configure:2857: $? = 0
    configure:2864: gcc -V >&5
    gcc-4.0: argument to `-V' is missing
    configure:2868: $? = 1
    configure:2891: checking for C compiler default output file name
    configure:2913: gcc    conftest.c  >&5
    ld: library not found for -lcrt1.10.5.o
    collect2: ld returned 1 exit status
    configure:2917: $? = 1
    configure:2955: result: 
    configure: failed program was:
    | /* confdefs.h.  */
    | #define PACKAGE_NAME ""
    | #define PACKAGE_TARNAME ""
    | #define PACKAGE_VERSION ""
    | #define PACKAGE_STRING ""
    | #define PACKAGE_BUGREPORT ""
    | #define PACKAGE "libevent"
    | #define VERSION "1.4.12-stable"
    | /* end confdefs.h.  */
    | 
    | int
    | main ()
    | {
    | 
    |   ;
    |   return 0;
    | }
    configure:2961: error: in `/tmp/libevent-1.4.12-stable':
    configure:2964: error: C compiler cannot create executables
    See `config.log' for more details.
    
    ## ---------------- ##
    ## Cache variables. ##
    ## ---------------- ##
    
    ac_cv_env_CCC_set=
    ac_cv_env_CCC_value=
    ac_cv_env_CC_set=
    ac_cv_env_CC_value=
    ac_cv_env_CFLAGS_set=
    ac_cv_env_CFLAGS_value=
    ac_cv_env_CPPFLAGS_set=
    ac_cv_env_CPPFLAGS_value=
    ac_cv_env_CPP_set=
    ac_cv_env_CPP_value=
    ac_cv_env_CXXCPP_set=
    ac_cv_env_CXXCPP_value=
    ac_cv_env_CXXFLAGS_set=
    ac_cv_env_CXXFLAGS_value=
    ac_cv_env_CXX_set=
    ac_cv_env_CXX_value=
    ac_cv_env_F77_set=
    ac_cv_env_F77_value=
    ac_cv_env_FFLAGS_set=
    ac_cv_env_FFLAGS_value=
    ac_cv_env_LDFLAGS_set=
    ac_cv_env_LDFLAGS_value=
    ac_cv_env_LIBS_set=
    ac_cv_env_LIBS_value=
    ac_cv_env_build_alias_set=
    ac_cv_env_build_alias_value=
    ac_cv_env_host_alias_set=
    ac_cv_env_host_alias_value=
    ac_cv_env_target_alias_set=
    ac_cv_env_target_alias_value=
    ac_cv_path_install='/usr/bin/install -c'
    ac_cv_prog_AWK=awk
    ac_cv_prog_ac_ct_CC=gcc
    ac_cv_prog_make_make_set=yes
    
    ## ----------------- ##
    ## Output variables. ##
    ## ----------------- ##
    
    ACLOCAL='${SHELL} /tmp/libevent-1.4.12-stable/missing --run aclocal-1.10'
    AMDEPBACKSLASH=''
    AMDEP_FALSE=''
    AMDEP_TRUE=''
    AMTAR='${SHELL} /tmp/libevent-1.4.12-stable/missing --run tar'
    AR=''
    AUTOCONF='${SHELL} /tmp/libevent-1.4.12-stable/missing --run autoconf'
    AUTOHEADER='${SHELL} /tmp/libevent-1.4.12-stable/missing --run autoheader'
    AUTOMAKE='${SHELL} /tmp/libevent-1.4.12-stable/missing --run automake-1.10'
    AWK='awk'
    BUILD_WIN32_FALSE=''
    BUILD_WIN32_TRUE=''
    CC='gcc'
    CCDEPMODE=''
    CFLAGS=''
    CPP=''
    CPPFLAGS=''
    CXX=''
    CXXCPP=''
    CXXDEPMODE=''
    CXXFLAGS=''
    CYGPATH_W='echo'
    DEFS=''
    DEPDIR=''
    DSYMUTIL=''
    ECHO='/bin/echo'
    ECHO_C='\c'
    ECHO_N=''
    ECHO_T=''
    EGREP=''
    EXEEXT=''
    F77=''
    FFLAGS=''
    GREP=''
    INSTALL_DATA='${INSTALL} -m 644'
    INSTALL_PROGRAM='${INSTALL}'
    INSTALL_SCRIPT='${INSTALL}'
    INSTALL_STRIP_PROGRAM='$(install_sh) -c -s'
    LDFLAGS=''
    LIBOBJS=''
    LIBS=''
    LIBTOOL=''
    LIBTOOL_DEPS=''
    LN_S=''
    LTLIBOBJS=''
    MAKEINFO='${SHELL} /tmp/libevent-1.4.12-stable/missing --run makeinfo'
    MKDIR_P='./install-sh -c -d'
    NMEDIT=''
    OBJEXT=''
    PACKAGE='libevent'
    PACKAGE_BUGREPORT=''
    PACKAGE_NAME=''
    PACKAGE_STRING=''
    PACKAGE_TARNAME=''
    PACKAGE_VERSION=''
    PATH_SEPARATOR=':'
    RANLIB=''
    SED=''
    SET_MAKE=''
    SHELL='/bin/sh'
    STRIP=''
    VERSION='1.4.12-stable'
    ac_ct_CC='gcc'
    ac_ct_CXX=''
    ac_ct_F77=''
    am__fastdepCC_FALSE=''
    am__fastdepCC_TRUE=''
    am__fastdepCXX_FALSE=''
    am__fastdepCXX_TRUE=''
    am__include=''
    am__isrc=''
    am__leading_dot='.'
    am__quote=''
    am__tar='${AMTAR} chof - "$$tardir"'
    am__untar='${AMTAR} xf -'
    bindir='${exec_prefix}/bin'
    build=''
    build_alias=''
    build_cpu=''
    build_os=''
    build_vendor=''
    datadir='${datarootdir}'
    datarootdir='${prefix}/share'
    docdir='${datarootdir}/doc/${PACKAGE}'
    dvidir='${docdir}'
    exec_prefix='NONE'
    host=''
    host_alias=''
    host_cpu=''
    host_os=''
    host_vendor=''
    htmldir='${docdir}'
    includedir='${prefix}/include'
    infodir='${datarootdir}/info'
    install_sh='$(SHELL) /tmp/libevent-1.4.12-stable/install-sh'
    libdir='${exec_prefix}/lib'
    libexecdir='${exec_prefix}/libexec'
    localedir='${datarootdir}/locale'
    localstatedir='${prefix}/var'
    mandir='${datarootdir}/man'
    mkdir_p='$(top_builddir)/./install-sh -c -d'
    oldincludedir='/usr/include'
    pdfdir='${docdir}'
    prefix='/usr/local'
    program_transform_name='s,x,x,'
    psdir='${docdir}'
    sbindir='${exec_prefix}/sbin'
    sharedstatedir='${prefix}/com'
    sysconfdir='${prefix}/etc'
    target_alias=''
    
    ## ----------- ##
    ## confdefs.h. ##
    ## ----------- ##
    
    #define PACKAGE_NAME ""
    #define PACKAGE_TARNAME ""
    #define PACKAGE_VERSION ""
    #define PACKAGE_STRING ""
    #define PACKAGE_BUGREPORT ""
    #define PACKAGE "libevent"
    #define VERSION "1.4.12-stable"
    
    configure: exit 77
    
    • Greg Hewgill
      Greg Hewgill about 12 years
      To save people hunting through your log, the real error is: ld: library not found for -lcrt1.10.5.o
    • Greg Hewgill
      Greg Hewgill about 12 years
      The question is, have you ever compiled anything else on this machine before, or is this the first time?
    • CourtDemone
      CourtDemone about 12 years
      I feel like I have, but it's a newer computer, so I might be thinking of my last one.
    • Greg Hewgill
      Greg Hewgill about 12 years
      Perhaps you could start with trying to compile a simple "hello world" program first, just to see whether you've got everything installed properly.
    • CourtDemone
      CourtDemone about 12 years
      What type of Hello World program would I be looking for? I gave a quick search and found a lot of stuff for C++ and Java, but I'm not exactly sure what I'm really dealing with here... This really isn't my strongest area.
    • Greg Hewgill
      Greg Hewgill about 12 years
      I'm afraid this question isn't really programming related, but more about installation of software. If you don't know anything about programming, then there are better places to find the kind of help you're looking for.
    • dmckee --- ex-moderator kitten
      dmckee --- ex-moderator kitten about 12 years
      I'm not sure I agree with the "not programming related" judgement. The issue her seem to be one of have the developer tools installed and configured ('course, I thought they were installed by default on Lion). If that is the case this would be "tools unique to the programming profession" or what ever it is that the FAQ says.
    • Andy Dent
      Andy Dent about 12 years
      I found this item because I'm experiencing a very similar problem trying to build an iOS library on a machine on which I've been definitely programming for some time. Seems very valid to me!
    • IpsRich
      IpsRich over 8 years
      This answer solved it for me - it was a licence thing.
  • earldouglas
    earldouglas almost 12 years
    This worked for me, thanks! I have a fresh installation of OSX 10.8 and the latest Xcode + Command Line Tools, so this doesn't seem to have been a problem related to upgrading OSX.
  • Misery
    Misery almost 12 years
    @James Great point. I too had a fresh installation of OSX 10.8.
  • Jonathan Larson
    Jonathan Larson over 11 years
    cd /Applications/Xcode.app/Contents/Developer/Toolchains;sudo ln -s XcodeDefault.xctoolchain OSX10.8.xctoolchain
  • Adrian Rodriguez
    Adrian Rodriguez over 11 years
    If you are reading this answer, this is definitely something you should do, but be aware that it will not solve your problem with other packages you are trying to build. So first install the command line tools then see the answer below by @sterescott and that should take care of your problems. Some packages like mod_jk use /usr/sbin/apxs -q CC in configure to ask for the C compiler. APXS spits it out, but it has the wrong path so that's why you keep getting errors.
  • Jazzy
    Jazzy over 11 years
    This helped, but the final fix came from here: glenscott.co.uk/blog/2011/08/29/…
  • james2doyle
    james2doyle almost 11 years
    In the config.log I saw that CC='/usr/bin/gcc-4.2' but I did an ls of the directory and there was nothing. So it was pretty clear this way the issue. I created the symlink and BAM! All good.
  • HSeldon
    HSeldon over 10 years
    After much searching this is exactly the trick I needed! Thanks-
  • JESii
    JESii over 10 years
    This worked for me; Xcode was install (clean Mavericks installation) but the command-line tools weren't automatically installed.
  • Raam Dev
    Raam Dev over 10 years
    This did not work for me. What worked for me was upgrading my command line tools (see stackoverflow.com/a/19993810/130664).
  • izilotti
    izilotti over 10 years
    Same thing on on Mavericks: sudo ln -s XcodeDefault.xctoolchain OSX10.9.xctoolchain
  • Blairg23
    Blairg23 almost 10 years
    This worked beautifully for me. I was installing iperf3 and I kept getting the error: "c compiler cannot install executables". I used "xcode-select --install" and it worked perfectly.
  • sapi
    sapi almost 10 years
    This seems to fix the issue on Yosemite; even though XCode 6 now comes with the command tools pre-installed, and I could run clang from the command line, ./configure failed until I ran xcode-select
  • Danny D'Amours
    Danny D'Amours almost 10 years
    Command line Tools packages ars now available at: developer.apple.com/downloads
  • schmijos
    schmijos over 9 years
    The important message from rbenv was for me: For most programs the llvm-gcc compiler works fine. However, versions of Ruby older than 1.9.3-p125 are incompatible with llvm-gcc. To build older versions of Ruby you must have the official GCC compiler installed on your system. TO FIX THE PROBLEM: Install Homebrew's apple-gcc42 package with this command: brew tap homebrew/dupes ; brew install apple-gcc42
  • Matt Sanders
    Matt Sanders over 9 years
    Some system/security updates seem to disable the license agreement and you have to go through this step again.
  • Patrick
    Patrick over 9 years
    +1 I was trying to build Tcl. There was already a gcc executable but Tcl was looking for gcc-4.0, so I just did: ln -s gcc gcc-4.0
  • Joel Day
    Joel Day almost 9 years
    Happened after an El Capitan beta install.
  • ephbaum
    ephbaum almost 9 years
    This worked for me on Yosemite as well: sudo ln -s XcodeDefault.xctoolchain OSX10.10.xctoolchain
  • reptilex
    reptilex over 8 years
    The same with OS X 10.9 sudo ln -s XcodeDefault.xctoolchain OSX10.9.xctoolchain
  • Marco Pelegrini
    Marco Pelegrini almost 8 years
    In Xcode 7 the Command Line Tools is located at the Locations tab. In my case I fixed the problem installing python by selecting Xcode 7.3.1
  • Alonso Urbano
    Alonso Urbano almost 8 years
    This worked for me in MacOS Sierra (beta 2) using Xcode 8.0b
  • Johannes Jander
    Johannes Jander over 7 years
    If someone is reading this in 2017 or later, you should set the system date back to feb 2013 or there will be an error claiming the Bluetooth pkg is untrusted. Some problem with an expired certificate.
  • Naidan
    Naidan about 7 years
    Thanks, this worked on OS X for running ./configure in for Apache
  • Artur79
    Artur79 almost 5 years
    Works on High Sierra too
  • Master
    Master over 3 years
    ln: gcc-4.2.1: Operation not permitted. I am getting this error when trying these steps.
  • Pradeep Kashyap
    Pradeep Kashyap over 2 years
    Or we can directly use this command its working for me sudo xcode-select --switch /Applications/Xcode.app