Gcc error: gcc: error trying to exec 'cc1': execvp: No such file or directory

Viewed 345764

I have been successfully using gcc on Linux Mint 12. Now I am getting an error. I have recently been doing some .so builds and installed Clang not to long ago, but have successfully compiled since both of those events, so not sure what has changed. I used the GUI Software Manager to remove and then install gcc again, but the results are the same:

~/code/c/ut: which gcc                                                                                                     
/usr/bin/gcc

~/code/c/ut: gcc -std=c99 -Wall -Wextra -g -c object.c                                                                      
gcc: error trying to exec 'cc1': execvp: No such file or directory
25 Answers

I experienced this soon after compiling and installing a shiny new GCC — version 8.1 — on RHEL 7. In the end, it ended up being a permissions problem; my root umask was the culprit. I eventually found cc1 hiding in /usr/local/libexec:

[root@nacelle gdb-8.1]# ls -l /usr/local/libexec/gcc/x86_64-pc-linux-gnu/8.1.0/ | grep cc1
-rwxr-xr-x 1 root root 196481344 Jul  2 13:53 cc1

However, the permissions on the directories leading there didn't allow my standard user account:

[root@nacelle gdb-8.1]# ls -l /usr/local/libexec/
total 4
drwxr-x--- 3 root root 4096 Jul  2 13:53 gcc
[root@nacelle gdb-8.1]# ls -l /usr/local/libexec/gcc/
total 4
drwxr-x--- 3 root root 4096 Jul  2 13:53 x86_64-pc-linux-gnu
[root@nacelle gdb-8.1]# ls -l /usr/local/libexec/gcc/x86_64-pc-linux-gnu/
total 4
drwxr-x--- 4 root root 4096 Jul  2 13:53 8.1.0

A quick recursive chmod to add world read/execute permissions fixed it right up:

[root@nacelle 8.1.0]# cd /usr/local/libexec
[root@nacelle lib]# ls -l | grep gcc
drwxr-x---  3 root root     4096 Jul  2 13:53 gcc
[root@nacelle lib]# chmod -R o+rx gcc
[root@nacelle lib]# ls -l | grep gcc
drwxr-xr-x  3 root root     4096 Jul  2 13:53 gcc

And now gcc can find cc1 when I ask it to compile something!

Just to complement @maxkoryukov's answer regarding Alpine.

The equivalent to Debian's build-essential in Alpine is build-base. In fact, the above mentioned alpine-sdk depends on build-base.

/ # apk info -R build-base
build-base-0.5-r1 depends on:
binutils
file
gcc
g++
make
libc-dev
fortify-headers

/ # apk info -R alpine-sdk
alpine-sdk-1.0-r0 depends on:
abuild
build-base
git

I experienced this problem on a reasonably fresh install of Fedora 27. I tried all the other suggestions or their equivalents; installing the various packages either said "already installed" or installed something new which didn't help.

Fixed with

# dnf remove gcc
# dnf install gcc gcc-c++

Im my rare case the PATH variable was set but not exported. Simply exporting the PATH variable was solving this problem.

For Amazon Linux Release 2 This will solve the issue:

sudo yum install gcc-c++

(This will not work: sudo yum install gcc72-c++)

It's in this package (Ubuntu 19.04):

  sudo apt install g++-6

In my rare case it was color wrapper who spoiled gcc. Solved by disabling cw excluding its directory /usr/libexec/cw from PATH environmental variable.

Why does this happen? When you install a fresh copy of linux, gcc compiler comes pre-packed with it. It only contains the files and binaries which are used to run the linux(to save space and time, obviously).

How to solve this error? All you need is to update your packages through the package manager and reinstall the build-essential packages. The commands might be different on different kernels.

Documenting another source of errors for installing gcc-10 on Amazon Linux 2 from source.

After running sudo make install and then testing gcc-10 I got this error:

gcc-10: fatal error: cannot execute ‘cc1’: execvp: No such file or directory

The reason was that the new g++ directories under /usr/local/ were created by sudo make install have 700 permissions so non-root users cannot see the directories content.

I fixed it by running

sudo find /usr/local/ -type d -exec chmod 755 {} \;

Note that I followed this snippet https://gist.github.com/nchaigne/ad06bc867f911a3c0d32939f1e930a11

Adding my solution for Amazon Linux - Working in 2021:

sudo yum install gcc

and then:

sudo yum install gcc-c++

I would like to add some additional answer, for the ones who the most liked answer didn't help.

I accidentally deleted some of files in /usr/lib and /usr/local/bin so apt couldn't reinstall gcc and build-essential packages correctly. I've tried almost everything, but, at the end only restoring the whole dependency tree helped. On Ubuntu 20.04 I've run the following:

sudo apt install --reinstall \
    binutils \
    binutils-common \
    binutils-x86-64-linux-gnu \
    cpp \
    cpp-9 \
    gcc \
    gcc-10-base \
    gcc-9 \
    gcc-9-base \
    libasan5 \
    libatomic1 \
    libbinutils \
    libc-dev-bin \
    libc6 \
    libc6-dev \
    libcc1-0 \
    libcrypt-dev \
    libcrypt1 \
    libctf-nobfd0 \
    libctf0 \
    libgcc-9-dev \
    libgcc-s1 \
    libgmp10 \
    libgomp1 \
    libidn2-0 \
    libisl22 \
    libitm1 \
    liblsan0 \
    libmpc3 \
    libmpfr6 \
    libquadmath0 \
    libstdc++6 \
    libtsan0 \
    libubsan1 \
    libunistring2 \
    linux-libc-dev \
    manpages \
    manpages-dev \
    zlib1g
Related