How do you fix a gcc compile 127 error? sudo apt-get install g++ doesn't work

41,208

Solution 1

You need to install g++ or some similarly named package to compile c++ code.

Solution 2

Install g++. This can be done e.g. by

sudo apt-get install g++ 

Not sure whether you really need a particular version. In most cases system default should be ok for it.

Solution 3

It's not about the g++. Check if you don't have any extra space or newline characters. If everything follows Makefile standard it should be ok. Additionally, check if you have specified the path correctly.

I hope I'll help somebody else, because I think you're over that problem.

Share:
41,208

Related videos on Youtube

user21839
Author by

user21839

Updated on September 18, 2022

Comments

  • user21839
    user21839 almost 2 years

    *emphasized text*when I try to run a program I get the following error.

    ubuntu@ubuntu-VirtualBox:~/Desktop$ make
    g++ -Wall -Wno-switch -I. -g   -c -o pass.o pass.cpp
    make: g++: Command not found
    make: *** [pass.o] Error 127
    

    I couldn't get gcc 4.8.2 installed because it said it couldn't find it. I did install 4.8

    I did the following to install gcc

    sudo add-apt-repository ppa:ubuntu-toolchain-f/test
    sudo apt-get update
    sudo apt-get install gcc-4.8
    

    next I did

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave     /usr/bin/g++ g++ /usr/bin/g++-4.6 
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
    sudo update-alternatives --config gcc
    

    the only thing I can think of is I don't have 4.8 when I type the command gcc -v it says
    gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)

    ok I run:

    ubuntu@ubuntu-VirtualBox:~$ sudo apt-get install g++
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    g++ is already the newest version.
    g++ set to manually installed.
    The following package was automatically installed and is no longer required:
    thunderbird-globalmenu
    Use 'apt-get autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 293 not upgraded.
    
    ubuntu@ubuntu-VirtualBox:~$ g++ -v
    The program 'g++' can be found in the following packages:
    * g++
    * pentium-builder
    Try: sudo apt-get install <selected package>
    
    ubuntu@ubuntu-VirtualBox:~/Desktop$ g++ --help | grep version
    The program 'g++' can be found in the following packages:
    * g++
    * pentium-builder
    Try: sudo apt-get install <selected package>
    ubuntu@ubuntu-VirtualBox:~/Desktop$ g++ --version
    The program 'g++' can be found in the following packages:
    * g++
    * pentium-builder
    Try: sudo apt-get install <selected package>
    ubuntu@ubuntu-VirtualBox:~/Desktop$ ^C
    ubuntu@ubuntu-VirtualBox:~/Desktop$
    

    this command installs

    sudo apt-get install g++-4.4 libstdc++6-4.4-dev 4.4 (I would like 4.8)
    
    ubuntu@ubuntu-VirtualBox:~/Desktop$ sudo apt-get install g++-4.4 libstdc++6-4.4-dev
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following extra packages will be installed:
    cpp-4.4 gcc-4.4 gcc-4.4-base
    Suggested packages:
    gcc-4.4-locales g++-4.4-multilib gcc-4.4-doc libstdc++6-4.4-dbg
    gcc-4.4-multilib libmudflap0-4.4-dev libgcc1-dbg libgomp1-dbg
    libmudflap0-dbg libcloog-ppl0 libppl-c2 libppl7 libstdc++6-4.4-doc
    
    The following NEW packages will be installed:
    cpp-4.4 g++-4.4 gcc-4.4 gcc-4.4-base libstdc++6-4.4-dev
    0 upgraded, 5 newly installed, 0 to remove and 292 not upgraded.
    Need to get 13.0 MB of archives.
    After this operation, 33.4 MB of additional disk space will be used.
    Do you want to continue [Y/n]? y
    Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main gcc-4.4-base i386 4.4.7-1ubuntu2 [12.0 kB]
    Get:2 http://us.archive.ubuntu.com/ubuntu/ precise/main cpp-4.4 i386 4.4.7-1ubuntu2 [3,606 kB]
    Get:3 http://us.archive.ubuntu.com/ubuntu/ precise/main gcc-4.4 i386 4.4.7-1ubuntu2 [3,079 kB]
    Get:4 http://us.archive.ubuntu.com/ubuntu/ precise/main libstdc++6-4.4-dev i386 4.4.7-1ubuntu2 [1,494 kB]
    Get:5 http://us.archive.ubuntu.com/ubuntu/ precise/main g++-4.4 i386 4.4.7-1ubuntu2 [4,780 kB]
    Fetched 13.0 MB in 3s (3,563 kB/s)   
    Selecting previously unselected package gcc-4.4-base.
    (Reading database ... 222776 files and directories currently installed.)
    Unpacking gcc-4.4-base (from .../gcc-4.4-base_4.4.7-1ubuntu2_i386.deb) ...
    Selecting previously unselected package cpp-4.4.
    Unpacking cpp-4.4 (from .../cpp-4.4_4.4.7-1ubuntu2_i386.deb) ...
    Selecting previously unselected package gcc-4.4.
    Unpacking gcc-4.4 (from .../gcc-4.4_4.4.7-1ubuntu2_i386.deb) ...
    Selecting previously unselected package libstdc++6-4.4-dev.
    Unpacking libstdc++6-4.4-dev (from .../libstdc++6-4.4-dev_4.4.7-1ubuntu2_i386.deb) ...
    Selecting previously unselected package g++-4.4.
    Unpacking g++-4.4 (from .../g++-4.4_4.4.7-1ubuntu2_i386.deb) ...
    Processing triggers for man-db ...
    Setting up gcc-4.4-base (4.4.7-1ubuntu2) ...
    Setting up cpp-4.4 (4.4.7-1ubuntu2) ...
    Setting up gcc-4.4 (4.4.7-1ubuntu2) ...
    Setting up g++-4.4 (4.4.7-1ubuntu2) ...
    Setting up libstdc++6-4.4-dev (4.4.7-1ubuntu2) ... 
    

    I have tried replacing 4.4 with 4.8 but it doesn't work. More importantly after using the 4.4 command above I still get the 127 error.

    I have been learning to program for the past month so when you answer please know I'm newer than new, and don't understand a lot if anything.

    • frlan
      frlan about 10 years
      Can you please run a locate g++ and a whereis g++
  • user21839
    user21839 about 10 years
    I did that but it didn't help much. Please take a look at my updated question details
  • user21839
    user21839 about 10 years
    I did that but it didn't help much. Please take a look at my updated question details