Gcc error: gcc: error trying to exec 'cc1'

2019-01-04 02:46发布

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

标签: gcc
16条回答
霸刀☆藐视天下
2楼-- · 2019-01-04 03:06

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

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-04 03:06

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

查看更多
闹够了就滚
4楼-- · 2019-01-04 03:07

1. Explanation

The error message told you, that the build-time dependency was not found, so all you need - install the appropriate package to your system (using package manager, build from sources or 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.

2. Solutions

Ubuntu / Linux Mint

sudo apt-get install --reinstall build-essential

Docker-alpine environment

If you are in docker-alpine environment, add this:

RUN apk add alpine-sdk

to your Dockerfile.

Taken from github

查看更多
何必那么认真
5楼-- · 2019-01-04 03:08

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!

查看更多
神经病院院长
6楼-- · 2019-01-04 03:11

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.)

查看更多
戒情不戒烟
7楼-- · 2019-01-04 03:11

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:

sudo yum install gcc72-c++

查看更多
登录 后发表回答