in

Resolving the "configure: error: C compiler cc is not found" Error When Compiling from Source

As a long-time Linux system administrator and open source enthusiast, I regularly find myself needing to compile software from source code. But that process can hit a snag right at the start with the dreaded "configure: error: C compiler cc is not found” message.

Based on my experience diagnosing and fixing this issue many times, I’ve put together this comprehensive guide on understanding the error, potential causes, and all the steps needed to get past it. Whether you are a fellow Linux geek or just getting started with compilers, read on to troubleshoot and resolve the missing C compiler error once and for all!

The Crucial Role of the C Compiler in Compiling from Source

Before jumping into solutions, it helps to understand exactly why the “cc” C compiler is required when compiling from source code.

The readme or install documentation for source code usually instructs you to run the standard commands:

./configure
make
make install

That ./configure script is checking that your system has all the necessary tools and dependencies installed to build the software from the source code. Without a compiler like gcc, it can’t actually compile all the underlying C/C++ source files into executable binaries.

The “cc” name specifically refers to the standard C compiler, which is assumed to be present by most configure scripts. Modern Linux systems mostly use gcc instead of classic cc, but the name still sticks around.

So in summary, the configure script fails with the missing C compiler error because it expects to find cc for compiling the core source code files, but cannot actually execute it successfully.

What Causes the Compiler to Go Missing?

Based on fixing this issue countless times, I‘ve narrowed down the main culprits behind a missing or broken cc compiler:

  • gcc and other compiler packages are not installed at all
  • gcc is installed but not added to the system PATH
  • Multiple compilers are installed and cc is misconfigured
  • The default cc -> gcc symlink is broken

On Linux distributions like Ubuntu, Debian, and CentOS, a C compiler will not come pre-installed. So often the issue is simply gcc or other compiler tools not being present.

However, I’ve also seen cases where gcc was installed, but the directory it resides in like /usr/local/bin was left out of the main system PATH variable. Even if installed, the OS can’t find gcc and execute it without that PATH configured properly.

Another tricky scenario is when multiple compilers are installed, or the cc symlink is overridden to point to something invalid like an old version of gcc or an alternative like clang. The configure script expects standard gcc for Linux builds typically.

And finally, it’s possible the symlink named cc that points to gcc gets corrupted or deleted, breaking that standard interface.

So in summary, there are a few common misconfigurations that can lead to the generic “C compiler not found” error. The solutions need to address the actual root cause.

Installing gcc and Other Compiler Toolchains

If the C compiler is outright missing on your system, the fix is straightforward – install a compiler! Here are the usual methods to install gcc and related tools on major Linux distributions:

Debian/Ubuntu

sudo apt install build-essential

The build-essential meta-package grabs gcc, g++, make and other necessary compilers and tools.

RHEL/CentOS

sudo yum groupinstall ‘Development Tools‘

OR

sudo yum install gcc gcc-c++ make

This installs gcc, g++ (the C++ compiler), and make from the Development Tools group, or individually.

Arch Linux

sudo pacman -S base-devel

The base-devel group includes gcc and the toolchain for Arch-based distros.

From Source

You can also install gcc from source, but that requires an existing C compiler like cc or gcc! So it‘s best to use the system package manager if possible.

In summary, installation commands can vary, but make sure a gcc package is installed through your Linux distribution‘s package manager. That will provide a working C compiler for most source builds.

Adding the Compiler Directory to Your System PATH

Assuming gcc is definitely installed but not found, the next culprit is usually the system PATH not including the compiler‘s directory. By default, gcc gets installed into a standard location like /usr/bin. But if that‘s not in your PATH, running cc or gcc in the shell can fail with a "not found" error.

Here is how I‘d troubleshoot and fix that:

First, find where gcc is installed by running:

which gcc

If it returns an empty result, gcc is not in the PATH.

Next, search the entire filesystem for the compiler:

  
sudo find / -name gcc

Take note of the installation directory, for example /usr/local/bin/gcc.

Then check your current system PATH with:

echo $PATH 

If the gcc path is missing, append it to PATH in your shell profile:

export PATH="$PATH:/usr/local/bin"

For other shells like zsh, edit .zshrc instead of .profile.

Finally, reload the profile or open a new shell to inherit the updated PATH.

Once the gcc directory is included, invoking cc or gcc should now work when attempting to compile!

Rather than fixing the system PATH, an alternative workaround is to just call gcc directly instead of cc when compiling.

Pass it as the argument for the compiler during configure:

 
./configure CC=gcc

This temporarily overrides cc to use gcc for that build.

The downside is having to do this for every compilation. Setting the PATH correctly avoids the extra step.

If you would rather fix the underlying cc symlink, first remove it:

sudo rm -f /usr/bin/cc 

Then recreate cc pointing to the gcc binary:

sudo ln -s /usr/bin/gcc /usr/bin/cc

Now cc and gcc both invoke the same compiler. This should only be needed if cc somehow got corrupted and no longer symlinks to gcc.

Other Tricky Causes of a Missing C Compiler

While most cases come down to gcc not being installed or found in the PATH, there are some other rare scenarios that could lead to compiler issues:

  • Multiple compilers like gcc and clang are installed, but cc still points at a missing or invalid one. Check it points to the expected gcc.

  • The architecture doesn‘t match between compiler and binaries. For example, gcc-multilib lets you install and switch between 32 and 64-bit compilers. Make sure it matches your system binaries.

  • The compiler requires extra environment variables or library paths to be set, like with gccgo or Rust‘s rustcc. Consult your distro‘s docs if using non-standard compilers.

  • gcc or cc symlinks are corrupted or misconfigured. Trace all symlinks from cc -> gcc -> actual binary and verify sane configurations.

  • You are attempting to install a very old version of gcc – sometimes newer dependencies and ABIs break on old source builds.

While convoluted, I‘ve bumped into each of these issues occasionally when compilers behave strangely. The core techniques like checking PATH and symlinks still apply, but you may need to do some deeper debugging for exotic toolchain issues.

Steps to Completely Install and Verify gcc on Ubuntu

To install, configure, and validate gcc and the cc linker on Ubuntu or similar Debian distributions, follow these steps:

  1. Install compiler toolchain:
      
    sudo apt install build-essential 
    
  2. Check gcc version:
    gcc --version
    
  3. Inspect gcc symlinks:
    ls -l /usr/bin/cc*
    
  4. Confirm gcc dir in PATH:
    echo $PATH
    
  5. If missing from PATH, add to profile:
    echo ‘export PATH="$PATH:/usr/bin"‘ >> ~/.profile
    
  6. Reload profile:
     
    source ~/.profile
    
  7. Re-attempt compiling the software!

These steps validate that gcc installs properly, cc symlinks correctly, and gcc is in the crucial system PATH. That comprehensive configuration should compile software smoothly!

Tips for Avoiding Issues When Compiling from Source

To avoid headaches when compiling software from source code, keep these tips in mind:

  • Always install the recommended build tools and compilers first – don’t assume they are included!

  • Check that your PATH includes common compiler directories like /usr/local/bin before compiling.

  • Pay close attention to configure script warnings about missing libraries or compilers.

  • Know exactly how cc invokes gcc on your Linux distribution and verify working symlinks.

  • Keep compilers updated through your package manager and don’t delete key symlinks!

  • Reference your distro’s documentation if using non-gcc compilers like clang, gccgo, etc.

  • Use virtual environments with custom compilers when possible to avoid conflicts.

  • Never blindly ignore compiler errors – take time to read and understand what failed!

In Closing

I hope this guide gives you a very thorough understanding of the “configure: error: C compiler cc is not found” error and how to resolve it once and for all! While frustrating, a methodical approach of checking your PATH, gcc installation, symlinks, and configurations can uncover what is amiss. Compiling from source is an essential skill for any Linux user, so be sure to validate your toolchain before jumping in. Your coding endeavors will build smoothly with a properly configured compiler environment.

Let me know if you have any other compiler war stories or tips! I’m always happy to help a fellow Linux enthusiast get past those pesky configuration issues. Write once, compile anywhere my friends.

AlexisKestler

Written by Alexis Kestler

A female web designer and programmer - Now is a 36-year IT professional with over 15 years of experience living in NorCal. I enjoy keeping my feet wet in the world of technology through reading, working, and researching topics that pique my interest.