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

172,140

Solution 1

You need to install gcc-c++ package.

yum install gcc-c++

Solution 2

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

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

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:


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

Solution 5

For apk, easiest way is:

apk add build-base

Share:
172,140
Zeyi Fan
Author by

Zeyi Fan

Updated on July 13, 2021

Comments

  • Zeyi Fan
    Zeyi Fan almost 3 years

    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:

    <?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

  • sirbrialliance
    sirbrialliance almost 12 years
    I had the same issue with my PATH environment when I ran strace g++ [args] I discovered it was trying the wrong folder in the path then giving up.
  • Jonathan Leffler
    Jonathan Leffler over 7 years
    Note that upper-case .C extension is one of a number of conventions for C++ source — .cpp and .cc are two others. The upper-case .C convention interacts badly with case-insensitive file systems (Windows, macOS, for example). When you had COLARR.C, the system was probably looking at it as a C++ source file; as colarr.c, it is a C source file.
  • Shadi
    Shadi over 7 years
    for alpine, this was apk add g++
  • Brana
    Brana almost 5 years
    This does not solve the problem, I did not find a way to change these links.
  • buxizhizhoum
    buxizhizhoum over 4 years
    It worked, and the error goes away after I modify the softlink of /etc/alternatives/gcc from /usr/bin/gcc72 to /usr/bin/gcc48 with ln -fs /usr/bin/gcc48 /etc/alternatives/gcc.
  • bfontaine
    bfontaine almost 3 years
    for Ubuntu this was apt install g++
  • Rahul Bharadwaj
    Rahul Bharadwaj over 2 years
    This was my case. I installed a new version of gcc and symlinked the gcc binary but forgot to symlink the g++ binary as well. Just ensure gcc -v and g++ -v show the same version.