0

I wanted to compile printf("Hello World!\r\n"); on my Nexus and installed sudo apt-get install gcc but if I compile using

gcc -x c++ helloworld.cpp -lstdc++ -o helloworld

I get the error

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

It once did run but after reinstalling ubuntu it only shows missing cc1plus error and as I am no specialist (just wanted to run something like system("service ssh stop"); or so) I want to ask what I can to to repair the gcc.

7
  • What is the name of your source code file, and how exactly are you trying to compile it? Pleased edit your question to include the complete command. Oct 15, 2016 at 12:13
  • I compile gcc -x c++ helloworld.cpp -lstdc++ -o helloworld but I will not change that as it worked once. Oct 15, 2016 at 12:20
  • So as I suspected you're telling gcc to treat the file as a C++ source file - in which case you will need to install g++ as well as plain gcc (the giveaway is exec 'cc1plus') Oct 15, 2016 at 12:30
  • When I try to install sudo apt-get install g++ I get the error E: You don't have enough free space in /var/cache/apt/archives/. where I tried sudo apt-get clean and sudo apt-get autoclean and even sudo apt autoremovewhat did not help. Oct 15, 2016 at 12:36
  • Well lack of space is something you will need to figure out yourself by uninstalling unneeded packages - if you have already installed gcc then the simplest thing would be to not try to compile it as g++ (since it appears to be plain 'C' syntax) i.e. either rename your source code file to hello.c or use gcc -x c - "I will not change that as it worked once" is not really a good argument here, IMHO. Oct 15, 2016 at 12:43

2 Answers 2

2

The error

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

arises because by using -x c++ and a .cpp filename suffix, you are telling gcc to treat your source code file as C++ rather than plain C, and do not have the g++ compiler installed.

Since printf("Hello World!\r\n"); does not use any C++ syntax elements, the simplest solution is to compile as plain C - either by renaming your file and omitting the -x directive:

gcc helloworld.c -o helloworld

or (if you want to keep the .cpp suffix), using -x to tell gcc to treat it as C regardless

gcc -x c helloworld.cpp -o helloworld

Note that in either case you will need to remove the -lstdc++ directive since the C++ standard library won't be available (or required).

0

install build-essential

c++ helloworld.cpp -o helloworld

you can

sudo rm -r /var/cache/*

4
  • 1
    Why rm -r /var/cache/*? What's that supposed to achieve? Oct 18, 2016 at 12:19
  • if you cant answer selfstate about that It's bad. Oct 19, 2016 at 21:05
  • I don't understand what you're saying. To clarify, I know what rm -r /var/cache/* does, but I would like to know why you find that effect desirable in this situation. Oct 20, 2016 at 1:41
  • Ah, I think I understand now: you're referring to OP's comment about the lack of space on /var. I didn't notice that comment before. You should probably make that clear to future readers so they don't start deleting their caches if they only suffer from the initial problem which is totally unrelated to the one outlined in the comments. Also, rm -r /var/cache/* doesn't just delete Apt caches and may only be a temporary solution for a more serious underlying problem. Oct 20, 2016 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.