[英]The compiler g++ can't create a.out file?
所以,我正在为我的C ++课做功课。 我在这个语句中编译了很长一段时间g++-5.2.0 -std=c++14 -Wall -Wextra -pedantic <file_name>
在终端时,由于某些原因我不知道,我收到了这条消息: Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
。
天真地,我运行了命令sudo g++-5.2.0 -std=c++14 -Wall -Wextra -pedantic hw2pr3.cpp
,输入我的密码,并同意这些条款。
现在,当我尝试使用g++-5.2.0 -std=c++14 -Wall -Wextra -pedantic hw2pr3.cpp
,我得到以下声明:
ld: can't write output file: a.out for architecture x86_64 collect2: error: ld returned 1 exit status
有人知道怎么办吗?
我现在尝试运行的文件(hw2pr3.cpp)与之前的文件有什么不同:
std::cout << std::setprecision(2) << "You should give away about $" << donate << ", save about $" << save <<", and live on about $" << live << ".\n";
我的猜测是std :: set precision(2)搞砸了(这是我第一次使用这个语句,我不知道我是否做得对),或者cout中的'$'是造成问题。
不,我无法提供完整的源代码; 这是我的作业,我不会在这里发布。
当您使用sudo g++-5.2.0
编译代码时,您以root身份运行编译器,因此输出文件a.out
以root身份创建。 如果没有sudo
,您将以普通用户身份运行,并再次尝试将输出写入a.out
。 但作为普通用户,您无权删除/覆盖根拥有的文件a.out
。
所以只是sudo rm a.out
,一切都应该好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.