Linux 编译错误:“g++:尝试执行'cc1plus'时出错:execvp:没有这样的文件或目录”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8878676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:05:50  来源:igfitidea点击:

Compile error: "g++: error trying to exec 'cc1plus': execvp: No such file or directory"

phpc++clinuxgcc

提问by Zeyi Fan

When I compile C/C++ program with popenin php... I got this error:

当我用popenin编译 C/C++ 程序时php......我收到了这个错误:

g++: error trying to exec 'cc1plus': execvp: No such file or directory

but if I run php code in shell.. it works fine..

但是如果我在shell中运行php代码..它工作正常..

in Arch Linux..

在 Arch Linux 中..

PHP Code:

PHP代码:

<?php
    function rfile($fp) {
    $out="";
       while (!feof($fp)) {
           $out.= fgets($fp, 1024000);
       }
       return $out;
    }
    $p = popen('g++ -Wall -g aplusb.cc -o aplusb 2>&1', 'r');
    $result = rfile($p);
    pclose($p);
    echo $result;
?>

thanks

谢谢

采纳答案by hahakubile

You need to install gcc-c++package.

你需要安装gcc-c++包。

yum install gcc-c++

回答by Freddy

Each compiler has its own libexec/ directory. Normally libexec directory contains small helper programs called by other programs. In this case, gcc is looking for its own 'cc1' compiler. Your machine may contains different versions of gcc, and each version should have its own 'cc1'. Normally these compilers are located on:

每个编译器都有自己的 libexec/ 目录。通常 libexec 目录包含其他程序调用的小帮助程序。在这种情况下,gcc 正在寻找它自己的“cc1”编译器。您的机器可能包含不同版本的 gcc,每个版本都应该有自己的“cc1”。通常这些编译器位于:


/usr/local/libexec/gcc/<architecture>/<compiler>/<compiler_version>/cc1

Similar path for g++. Above error means, that the current gcc version used is not able to find its own 'cc1' compiler. This normally points to a PATH issue.

g++ 的类似路径。以上错误意味着,当前使用的 gcc 版本无法找到它自己的“cc1”编译器。这通常指向 PATH 问题。

回答by rtrigoso

I had the same issue with gcc "gnat1" and it was due to the path being wrong. Gnat1 was on version 4.6 but I was executing version 4.8.1, which I had installed. As a temporary solution, I copied gnat1 from 4.6 and pasted under the 4.8.1 folder.

我对 gcc "gnat1" 有同样的问题,这是由于路径错误。Gnat1 使用的是 4.6 版,但我正在执行已安装的 4.8.1 版。作为临时解决方案,我从 4.6 复制了 gnat1 并粘贴到 4.8.1 文件夹下。

The path to gcc on my computer is /usr/lib/gcc/i686-linux-gnu/

我电脑上gcc的路径是/usr/lib/gcc/i686-linux-gnu/

You can find the path by using the find command:

您可以使用 find 命令找到路径:

find /usr -name "gnat1"

In your case you would look for cc1plus:

在你的情况下,你会寻找 cc1plus:

find /usr -name "cc1plus"

Of course, this is a quick solution and a more solid answer would be fixing the broken path.

当然,这是一个快速的解决方案,更可靠的答案是修复损坏的路径。

回答by Sunil Kumar

I don't know why but i just renamed my source file COLARR.C to colarr.c and the error vanished! probably you need this

我不知道为什么,但我只是将我的源文件 COLARR.C 重命名为 colarr.c 并且错误消失了!可能你需要这个

sudo apt-get install g++

回答by pulkitag

This problem can happen if different versions of g++ and gcc are installed.

如果安装了不同版本的 g++ 和 gcc,就会出现这个问题。

   g++ --version
   gcc --version

If these don't give the result, you probably have multiple versions of gcc installed. You can check by using:

如果这些没有给出结果,您可能安装了多个版本的 gcc。您可以使用以下方法进行检查:

    dpkg -l | grep gcc | awk '{print }'

Usually, /usr/bin/gcc will be sym-linked to /etc/alternatives/gcc which is again sym-linked to say /usr/bin/gcc-4.6 or /usr/bin/gcc-4.8 (In case you have gcc-4.6, gcc-4.8 installed.)

通常,/usr/bin/gcc 将被符号链接到 /etc/alternatives/gcc,它再次被符号链接表示 /usr/bin/gcc-4.6 或 /usr/bin/gcc-4.8(如果你有已安装 gcc-4.6、gcc-4.8。)

By changing this link you can make gcc and g++ run in the same version and this may resolve your issue!

通过更改此链接,您可以使 gcc 和 g++ 在同一版本中运行,这可能会解决您的问题!

回答by vliu

I had the same issue when forking with 'python'; the main reason is that the search path is relative, if you don't call g++as /usr/bin/g++, it will not be able to work out the canonical paths to call cc1plus.

使用“python”分叉时,我遇到了同样的问题;主要原因是搜索路径是相对的,如果你不调用g++as /usr/bin/g++,它将无法计算出调用的规范路径cc1plus

回答by David Hamner

Install g++ on openSuSE run

在 openSuSE 运行上安装 g++

zypper in gcc-c++

回答by tsveti_iko

Something went wrong with your GCCinstallation. Try reinstalling the it like this:

您的GCC安装出现问题。尝试像这样重新安装它:

sudo apt-get install --reinstall g++-5

In Ubuntu the g++is a dependency package that installs the default version of g++for your OS version. So simply removing and installing the package again won't work, cause it will install the default version. That's why you need to reinstall.

在 Ubuntu 中,它g++是一个依赖包,它g++为您的操作系统版本安装默认版本。因此,简单地再次删除并安装该软件包是行不通的,因为它将安装默认版本。这就是您需要重新安装的原因。

Note: You can replace the g++-5with your desired g++version. To find your current g++version run this:

注意:您可以将 替换为g++-5您想要的g++版本。要查找您当前的g++版本,请运行:

g++ --version

回答by Slava

You may have this issue as well if you have environment variable GCC_ROOT pointing to a wrong location. Probably simplest fix could be (on *nix like system):

如果您的环境变量 GCC_ROOT 指向错误的位置,您也可能会遇到此问题。可能最简单的修复可能是(在 *nix 之类的系统上):

unset GCC_ROOT

in more complicated cases you may need to repoint it to proper location

在更复杂的情况下,您可能需要将其重新指向正确的位置