Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The compiler g++ can't create a.out file?

So, I was doing the homework for my C++ class. I was compiling for quite awhile with this statement g++-5.2.0 -std=c++14 -Wall -Wextra -pedantic <file_name> in terminal when, for some reason unbeknownst to me, I received this message: Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo..

Naively, I ran the command sudo g++-5.2.0 -std=c++14 -Wall -Wextra -pedantic hw2pr3.cpp, entered in my password, and agreed to the terms.

Now, when I try to compile with g++-5.2.0 -std=c++14 -Wall -Wextra -pedantic hw2pr3.cpp, I get this statement:

ld: can't write output file: a.out for architecture x86_64 collect2: error: ld returned 1 exit status

Does anybody know what to do about this?

What's different about the file that I am trying to run now (hw2pr3.cpp) than the files previously is this line:

std::cout << std::setprecision(2) << "You should give away about $" << donate << ", save about $" << save <<", and live on about $" << live << ".\n";

My guess is that either the std::set precision(2) messed it up (this is my first time to use this statement and I don't know if I did it right), or that the '$' in the cout is causing issues.

No, I cannot provide the full source code for this; this is my homework and I will not post it on here.

like image 682
K. Shores Avatar asked Sep 26 '22 17:09

K. Shores


1 Answers

When you compiled your code with sudo g++-5.2.0, you ran the compiler as root, so the output file a.out was created as root. Without sudo, you are running as an ordinary user, and again trying to write the output to a.out. But as an ordinary user, you don't have permission to delete / overwrite the root-owned file a.out.

So just sudo rm a.out and all should be well.

like image 155
Nate Eldredge Avatar answered Sep 29 '22 05:09

Nate Eldredge