171

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
Scooter
  • 6,802
  • 8
  • 41
  • 64
  • 1
    Possible duplicate of [\`gcc: error trying to exec 'cc1': execvp: No such file or directory\` When compile program with \`popen\` in php](http://stackoverflow.com/questions/8878676/gcc-error-trying-to-exec-cc1-execvp-no-such-file-or-directory-when-compil) – Ciro Santilli OurBigBook.com Aug 09 '16 at 14:55

26 Answers26

162

Explanation

The error message told us, that the build-time dependency (in this case it is cc1) was not found, so all we need — install the appropriate package to the system (using package manager // from sources // another way)

What is cc1:

cc1 is the internal command which takes preprocessed C-language files and converts them to assembly. It's the actual part that compiles C. For C++, there's cc1plus, and other internal commands for different languages.

taken from this answer by Alan Shutko.

Solution for: Ubuntu / Linux Mint

sudo apt-get update
sudo apt-get install --reinstall build-essential

Solution for: Docker-alpine environment

If you are in docker-alpine environment install the build-base package by adding this to your Dockerfile:

RUN apk add build-base

Better package name provided by Pablo Castellano. More details here.

If you need more packages for building purposes, consider adding of the alpine-sdk package:

RUN apk add alpine-sdk

Taken from github

Solution for: CentOS/Fedora

This answer contains instructions for CentOS and Fedora Linux

Solution for: Amazon Linux

sudo yum install gcc72-c++

Taken from this comment by CoderChris

You could also try to install missed dependencies by this (though, it is said to not to solve the issue):

sudo yum install gcc-c++.noarch

Taken from this answer

maxkoryukov
  • 4,205
  • 5
  • 33
  • 54
  • 4
    did not work for me on Ubuntu 20.04.2 – exebook Oct 24 '21 at 05:43
  • @execbook : https://linuxize.com/post/how-to-install-gcc-on-ubuntu-20-04/ , but nothing actually changed, the same `build-essential` package resolves the problem – maxkoryukov Oct 25 '21 at 19:04
  • 5
    For Amazon Linux 2, `sudo yum install gcc72-c++` didn't work for me but `sudo yum install gcc-c++` worked fine. – PApostol Nov 26 '21 at 12:35
  • 1
    Excellent, thorough answer @maxkoryukov. I did learn from it. Thank you! – EmEs Dec 07 '21 at 11:09
  • 1
    In OpenSuse running `zypper install -t pattern devel_basis` won't install C++, run `zypper install gcc-c++` to add also that. – Jari Turkia Jan 14 '22 at 13:59
  • For posterity, it was trying to install python's spare-dot-topn that led me here (https://stackoverflow.com/questions/70754148/error-installing-sparse-dot-topn-on-aws-ec2-could-not-build-wheels-for-sparse) [twice apparently] – jtlz2 Aug 17 '22 at 08:02
  • 1
    For RHEL/8 `sudo yum install gcc-c++` worked for me. – dan Jun 07 '23 at 15:41
103

On CentOS or Fedora

yum install gcc-c++ 
Mart Van de Ven
  • 378
  • 2
  • 8
Antony Hatchkins
  • 31,947
  • 10
  • 111
  • 111
71

On debian / ubuntu I fixed this problem by reinstalling build-essential:

sudo apt-get update
sudo apt-get install --reinstall build-essential
mchid
  • 2,699
  • 1
  • 14
  • 12
  • 1
    In the log for the ´--reinstall build-essential´ my ubuntu specifically stated "Setting up g++ (4:6.1.1-1ubuntu2) ... update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode" – Paamand Feb 10 '17 at 08:42
  • This fixed me on Debian DigitalOcean.com droplet. I only had to run the second command shown though and after that gcc compiled by .cpp file perfectly. – raddevus Feb 10 '17 at 15:50
  • 1
    @mchid Nothing wrong - It fixed the problem. Just wanted to clarify what part of you suggestion related to the problem. E.g. if your answer did not work for someone they could use the update-alternative specific for the gcc. – Paamand Feb 13 '17 at 09:44
29

This is because gcc calls many other executables to complete the processing of the input, and cc1 is not in the included path.

On shell type whereis cc1. If cc1 is found, it's better go ahead and create a softlink in the directory of gcc; otherwise, cc1 is not installed and you have to install gcc-c++ using the package manager.

apaderno
  • 28,547
  • 16
  • 75
  • 90
perilbrain
  • 7,961
  • 2
  • 27
  • 35
  • 5
    Thanks for the reply. whereis cc1 returns nothing. I have gcc and gcc-4.4, gcc-4-6, libgcc1 installed according to Software Manager. I just install g++, but I am still getting the error. – Scooter Aug 11 '12 at 08:02
  • 2
    see if the executable is present in /usr/local/libexec/gcc////cc1 otherwise for temporary usage navigate to /usr/bin and create link by `ln -s cc cc1` – perilbrain Aug 11 '12 at 08:14
  • I don't have a /usr/local/libexec directory. There is no "gcc" found under /usr/local. – Scooter Aug 11 '12 at 08:22
  • 1
    GCC is under /usr/bin and there you will cc as well,execute the command mentioned in previous comment in this directory. – perilbrain Aug 11 '12 at 08:24
  • I did find: /usr/lib/gcc/x86_64-linux-gnu/4.6/cc1 /usr/lib/gcc/x86_64-linux-gnu/4.4/cc1 – Scooter Aug 11 '12 at 08:31
  • I added the above to my path and gcc now says "gcc: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found compilation terminated." – Scooter Aug 11 '12 at 08:37
  • I don't know how this happened. I would like to remove gcc and reinstall, but doing the "remove" from the Software Manager and "Install" got me the same problem. One that I am am just now getting after months of OK usage?? – Scooter Aug 11 '12 at 08:38
  • The tip to install `gcc-c++` got me moving again after a day of frustration! – vpipkt Jun 03 '16 at 12:53
  • 3
    The cc1/cc1plus binaries are NOT supposed to be in $PATH. – zwol Jan 10 '17 at 12:49
  • Thanks! This solution is what's needed for users of Amazon Linux - just a note to future visitors! – hamx0r Feb 02 '17 at 19:22
19

Amazon Linux: fixing GCC issue

Since this comes up as the first result on Google, I just wanted to document my experience with Amazon Linux. Installing gcc-c++.noarch fixed the problem:

sudo yum install gcc-c++.noarch

Some people also reported this alternative as a solution (@CoderChris):

sudo yum install gcc72-c++

Others reported doing sudo yum install gcc first, then sudo yum install gcc-c++. (@Wilmer E. Henao, @Talha Anwar)

Renato Byrro
  • 3,578
  • 19
  • 34
15

I fixed this problem by explicitly installing g++:

sudo apt-get install g++

Problem was encountered on Ubuntu 12.04 while installing pandas. (Thanks perilbrain.)

Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
14

I ran into a similar issue today - a co-worker could not build his software but I could build it. When he ran gcc it could not find cc1.

His executable path looked reasonable but the fact that I could not easily replicate the failure suggested something in his environment as the cause.

Eventually we found GCC_EXEC_PREFIX defined in his environment which was the culprit and was misleading gcc in the search for cc1. This was part of his shell startup scripts and was meant to work around a limitation on a SPARC/Solaris system that is no longer in use. The problem was resolved by not setting this environment variable.

http://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html

andr
  • 15,970
  • 10
  • 45
  • 59
deaks
  • 243
  • 5
  • 9
  • Exact same problem.. still unresolved! This occurred after porting the project from 16.04LTS to 18.04LTS. – Shaze Aug 02 '19 at 15:51
9

yum install gcc-c++ did the fix.

BSMP
  • 4,596
  • 8
  • 33
  • 44
Suresh Ganta
  • 135
  • 1
  • 5
  • 1
    duplicate of an existing answer (currently the highest voted one, posted a year before this one). "Thanks" or "me too" answers are just clutter. – Peter Cordes Dec 03 '19 at 07:23
5

Make sure your GCC_EXEC_PREFIX(env) is not exported and your PATH is exported to right tool chain.

Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
Vijay Nag
  • 101
  • 1
  • 2
4

Adding my solution for Amazon Linux - Working in 2021:

sudo yum install gcc

and then:

sudo yum install gcc-c++
Wilmer E. Henao
  • 4,094
  • 2
  • 31
  • 39
3

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!

jefe2000
  • 406
  • 6
  • 13
3

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
3

For Amazon Linux Release 2 This will solve the issue:

sudo yum install gcc-c++

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

dwto
  • 278
  • 1
  • 7
1

This might also be the displayed error message if you try to run 32-bit gcc binaries on a 64-bit OS and missing 32-bit glibc. According to this readme: "For 64 bit system, 32 bit libc and libncurses are required to run the tools.". In this case there is no problem with the path and cc1 is actually found, but reported as missing as no 32 bit glibc.

Community
  • 1
  • 1
sfrank
  • 121
  • 1
  • 5
1

What helped for me was to use llvm-gcc instead:

ln -s $(which llvm-gcc) /usr/local/bin/gcc
Alex
  • 2,398
  • 1
  • 16
  • 30
1

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++
wallyk
  • 56,922
  • 16
  • 83
  • 148
1

On Scientific Linux 6 (similar to CentOS 6-- SL is now replaced by CentOS, AIUI), I had to use /usr/sbin/prelink -av -mR which I found suggested at https://stelfox.net/blog/2014/08/dependency-prelink-issues/

Until I did that, I got a cc1 error gcc: error trying to exec 'cc1': execvp: No such file or directory when I tried to compile, and gcc --version reported 4.2.2 instead of 4.4.7, despite that version being reported by yum.

It may or may not be related, but the system had run out of space on /var

1

Just to document my trouble with this issue even though it just appears to be a specific example of other answers; as a relative newbie I feel like this might help others.

Solution:

I added '/usr/bin' to the beginning of PATH for a single session using PATH='/usr/path/:$PATH' and everything started to work fine.

I used gedit to update the PATH permanently, after ensuring it wouldn't break my regular toolchains.

Explanation:

I have multiple toolchains installed on Ubuntu 14.04LTS and I use just a couple on a regular basis. When I tried to use gcc from the command line I got the issue describe by the OP. '/usr/bin' is in the PATH but it is behind the other toolchain locations. Turns out the cc1 for those other toolchains is incompatible with gcc.

J.Sunderland
  • 50
  • 1
  • 3
1

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
Pavel.Zh
  • 437
  • 3
  • 15
0

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.

user3132194
  • 2,381
  • 23
  • 17
0

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.

yoismak
  • 45
  • 2
  • 9
0

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

k1000
  • 145
  • 1
  • 1
  • 7
0

Just an example. You might find your cc1 installed on other places depends on whatever software was installed before.

find /usr/ -name "*cc1*"
# out:  /usr/share/terminfo/x/xterm+pcc1
# out:  /usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1
# out: /usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1plus
export PATH=$PATH:/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/

credit belong to programmerah

And of course, this is more from the Pen tester perspective. Please using proper method to resolve it like other answers mentioned.

Alvin Smith
  • 547
  • 5
  • 9
-1

You can fix that by running this: On Fedora:

sudo dnf install redhat-rpm-config
victor sosa
  • 899
  • 13
  • 27
-1

It's in this package (Ubuntu 19.04):

  sudo apt install g++-6
olealgo
  • 479
  • 11
  • 23
  • You don't need to install an old G++ version; just `g++` is fine. Or better, `build-essential` pulls in some libs too. – Peter Cordes Dec 03 '19 at 07:25
-1

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

Oplatek
  • 350
  • 2
  • 13