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


Php Problem Overview

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

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

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

in Arch Linux..

PHP Code:

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


Php Solutions

Solution 1 - Php

You need to install gcc-c++ package.

yum install gcc-c++

Solution 2 - Php

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

sudo apt-get install g++

Solution 3 - Php

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

   g++ --version
   gcc --version

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

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

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

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

Solution 4 - Php

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:


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.

Solution 5 - Php

For apk, easiest way is:

apk add build-base

Solution 6 - Php

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.

Solution 7 - Php

Install g++ on openSuSE run

zypper in gcc-c++

Solution 8 - Php

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

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.

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

g++ --version

Solution 9 - Php

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

unset GCC_ROOT

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

Solution 10 - Php

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.

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

You can find the path by using the find command:

find /usr -name "gnat1"

In your case you would look for cc1plus:

find /usr -name "cc1plus"

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


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZeyi FanView Question on Stackoverflow
Solution 1 - PhphahakubileView Answer on Stackoverflow
Solution 2 - PhpSunil KumarView Answer on Stackoverflow
Solution 3 - PhppulkitagView Answer on Stackoverflow
Solution 4 - PhpFreddyView Answer on Stackoverflow
Solution 5 - PhpMyothaView Answer on Stackoverflow
Solution 6 - PhpvliuView Answer on Stackoverflow
Solution 7 - PhpDavid HamnerView Answer on Stackoverflow
Solution 8 - Phptsveti_ikoView Answer on Stackoverflow
Solution 9 - PhpSlavaView Answer on Stackoverflow
Solution 10 - Phpren.rocksView Answer on Stackoverflow