- Gcc error: gcc: error trying to exec ‘cc1’: execvp: No such file or directory
- 26 Answers 26
- Explanation
- Solution for: Ubuntu / Linux Mint
- Solution for: Docker-alpine environment
- Solution for: CentOS/Fedora
- Solution for: Amazon Linux
- Amazon Linux: fixing GCC issue
- gcc/g++: «No such file or directory»
- 3 Answers 3
- How to tell the compiler where to find it
- Difference between #include and #include «bar»
- Details on <> / «» -priorities and -I
- How to fix the error “gcc no such file or directory”
- Resolve the problem “gcc no such file or directory”?
- Reason: Missing GCC
- Solution: Install the GCC
- Method 1: Using apt
- Method 2: Using build essentials
- Conclusion
Gcc error: gcc: error trying to exec ‘cc1’: execvp: No such file or directory
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
26 Answers 26
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)
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.
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 :
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:
Solution for: CentOS/Fedora
This answer contains instructions for CentOS and Fedora Linux
Solution for: Amazon Linux
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
For Amazon Linux 2, sudo yum install gcc72-c++ didn’t work for me but sudo yum install gcc-c++ worked fine.
In OpenSuse running zypper install -t pattern devel_basis won’t install C++, run zypper install gcc-c++ to add also that.
On debian / ubuntu I fixed this problem by reinstalling build-essential :
sudo apt-get update sudo apt-get install --reinstall build-essential
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»
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.
@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.
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.
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.
see if the executable is present in /usr/local/libexec/gcc/
GCC is under /usr/bin and there you will cc as well,execute the command mentioned in previous comment in this directory.
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):
Others reported doing sudo yum install gcc first, then sudo yum install gcc-c++ . (@Wilmer E. Henao, @Talha Anwar)
I fixed this problem by explicitly installing g++:
Problem was encountered on Ubuntu 12.04 while installing pandas. (Thanks perilbrain.)
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.
Exact same problem.. still unresolved! This occurred after porting the project from 16.04LTS to 18.04LTS.
yum install gcc-c++ did the fix.
duplicate of an existing answer (currently the highest voted one, posted a year before this one). «Thanks» or «me too» answers are just clutter.
Make sure your GCC_EXEC_PREFIX(env) is not exported and your PATH is exported to right tool chain.
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!
gcc/g++: «No such file or directory»
It is the same when compiling C-programs with gcc . Why is that? Please note: This question has been asked many times before, but each time it was specific to the askers situation. This question’s purpose is to have a question that others can be closed as duplicates of, once and for all; a FAQ.
3 Answers 3
Your compiler just tried to compile the file named foo.cc . Upon hitting line number line , the compiler finds:
The compiler then tries to find that file. For this, it uses a set of directories to look into, but within this set, there is no file bar . For an explanation of the difference between the versions of the include statement look here.
How to tell the compiler where to find it
g++ has an option -I . It lets you add include search paths to the command line. Imagine that your file bar is in a folder named frobnicate , relative to foo.cc (assume you are compiling from the directory where foo.cc is located):
You can add more include-paths; each you give is relative to the current directory. Microsoft’s compiler has a correlating option /I that works in the same way, or in Visual Studio, the folders can be set in the Property Pages of the Project, under Configuration Properties->C/C++->General->Additional Include Directories.
Now imagine you have multiple version of bar in different folders, given:
// A/bar #include std::string which() < return "A/bar"; >
// B/bar #include std::string which() < return "B/bar"; >
// C/bar #include std::string which() < return "C/bar"; >
// foo.cc #include "bar" #include int main ()
The priority with #include «bar» is leftmost:
$ g++ -IA -IB -IC foo.cc $ ./a.out A/bar
As you see, when the compiler started looking through A/ , B/ and C/ , it stopped at the first or leftmost hit.
This is true of both forms, include <> and incude «» .
Difference between #include and #include «bar»
Usually, the #include makes it look into system folders first, the #include «xxx» makes it look into the current or custom folders first.
Imagine you have the following files in your project folder:
For this, your compiler will #include the file list in your project folder, because it currently compiles main.cc and there is that file list in the current folder.
and then g++ main.cc , your compiler will look into the system folders first, and because is a standard header, it will #include the file named list that comes with your C++ platform as part of the standard library.
This is all a bit simplified, but should give you the basic idea.
Details on <> / «» -priorities and -I
According to the gcc-documentation, the priority for include <> is, on a «normal Unix system», as follows:
/usr/local/include libdir/gcc/target/version/include /usr/target/include /usr/include
For C++ programs, it will also look in /usr/include/c++/version, first. In the above, target is the canonical name of the system GCC was configured to compile code for; [. ].
The documentation also states:
You can add to this list with the -Idir command line option. All the directories named by -I are searched, in left-to-right order, before the default directories. The only exception is when dir is already searched by default. In this case, the option is ignored and the search order for system directories remains unchanged.
To continue our #include / #include»list» example (same code):
and indeed, the -I. prioritizes the folder . over the system includes and we get a compiler error.
How to fix the error “gcc no such file or directory”
The GCC (GNU Compiler Collection) is a standard compiler used in Linux to compile C/C++ programs. With the help of GCC, we can compile the program straight in the terminal. Often times when dealing with GCC, an error can be prompted with the statement “unable to execute gcc no such file or directory”.
This article provides possible reasons that invoke the problem with the statement “gcc no such file or directory”. Furthermore, we have demonstrated the solution as well.
Resolve the problem “gcc no such file or directory”?
There are some diverse reasons that can invoke this error. In this section reasons for the problem will be explained as well as the methods of how to fix it.
Reason: Missing GCC
The first most obvious reason is that your system does not have the gcc installed on it. You can verify the installation of GCC using the following command in your Linux terminal:
If this command returns the following error, this means that gcc is not installed on your system:
Solution: Install the GCC
To fix the issue you simply need to install the GNU compiler collection onto your system. Let’s elaborate on how GCC will be installed. There are two distinct methods through which this can be achieved.
Method 1: Using apt
The simplest way is to use the apt installer to install GCC. Simply run the following command:
The snippet above shows that gcc will successfully be installed using the apt installer.
Method 2: Using build essentials
The second method is to install build-essentials onto your system which will also include the gcc. Run the commands below into the terminal to execute it:
$ sudo apt update $ sudo apt install build-essential
Once you have installed gcc on your system using either of the methods, it can be double-checked using the command mentioned below:
This proves that GCC has now been installed. The process should remove the “gcc no such file or directory” error during an attempt to compile any files.
Conclusion
The “gcc no such file or directory” issue occurs when the gcc is not installed in your system. To install GCC, you can use either the command “sudo apt install gcc” or the alternate command “sudo apt install build-essential” command. Here, you have learned the reason for the error “gcc no such file or directory” and the two methods to fix this error.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY