5

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.

K. Shores
  • 875
  • 1
  • 18
  • 46
  • If you want help you may have to strip out the parts that would be identifiable as the assignment and provide a generic example that reproduces the problem. – ChiefTwoPencils Sep 19 '15 at 04:54
  • Can you compile anything at all? Can you compile and run Hello World? This seems more like something wrong with the compiler environment, rather than your code. – Nate Eldredge Sep 19 '15 at 04:54
  • @NateEldredge Yes, I can compile and run hello world. – K. Shores Sep 19 '15 at 05:12
  • @NateEldredge Thank you very much! That fixed it. Do you happen to know why Xcode would have sent that statement? – K. Shores Sep 19 '15 at 05:24
  • Googling the message is a good start and turns up http://stackoverflow.com/questions/26197347/agreeing-to-the-xcode-ios-license-requires-admin-privileges-please-re-run-as-r – Nate Eldredge Sep 19 '15 at 05:25

1 Answers1

4

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.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82