Linux – gcc – error: no acceptable C compiler found in $PATH

compilergcclinuxsoftware installation

I am trying to install GCC from source. I am following the instructions on the wiki at https://gcc.gnu.org/wiki/InstallingGCC and also on this question on SO.
I am running into issues on the configure step when running:

$PWD/../gcc-4.6.2/configure --prefix=$HOME/gcc-4.6.2

I get the following output and error:

checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking for libatomic support... yes
checking for libcilkrts support... no
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for libmpx support... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/bin/objdir':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

I appears as if the error is because there is no C compiler installed. This confuses me because isn't installing a C compiler what installing GCC is supposed to do? All the solutions I can find for this error say that I need to install GCC, so how can I install GCC if I need GCC installed to do it?

I have updated my $PATH variable using export PATH=$PATH:/usr/bin/gcc-4.6.2 but it didn't help. I have also looked at this similar question without success: https://unix.stackexchange.com/questions/310669/c-compiler-while-installing-gcc

Is there something I am missing? What else can I do to get GCC installed?

NOTE: I can't just use yum or apt-get to install it because I am using a custom distribution that does not have those type of installer software installed.

Best Answer

GCC itself is written in C. Thus, in order to install it, you need a C compiler. This is a catch-22. You're not missing anything. In fact, there is a rather famous Ken Thompson essay, “Reflections on Trusting Trust” reflecting upon a related aspect.

You need to get a C compiler from somewhere. Whoever built your custom distribution surely had one, as you can't build a Linux kernel without it either. They ought to make it available somewhere.

Other than that, you'll have to cross-compile gcc (and binutils, and C library headers, etc.) from a distro where you can install a compiler. This is how someone builds the a distro for a new platform. It's also possible that if your platform is embedded, no one expects you to run gcc on the device itself, and instead they expect you to cross-compile any software you need for the device. In that case, your embedded distro should provide the cross-compiler to use.

Related Question