c++ - 编译器 g++ 无法创建 a.out 文件?

标签 c++ xcode gcc compiler-errors c++14

所以,我正在为我的 C++ 类(class)做作业。我用这条语句编译了很长时间 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) 把它搞砸了(这是我第一次使用这个语句,我不知道我做对了没有),或者是 '$' in cout 引起了问题。

不,我不能为此提供完整的源代码;这是我的作业,我不会把它贴在这里。

最佳答案

当您使用 sudo g++-5.2.0 编译代码时,您以 root 身份运行编译器,因此输出文件 a.out 是以 root 身份创建的。如果没有 sudo,您将以普通用户身份运行,并再次尝试将输出写入 a.out。但是作为普通用户,您没有权限删除/覆盖 root 拥有的文件 a.out

所以只要 sudo rm a.out 一切都会好起来的。

关于c++ - 编译器 g++ 无法创建 a.out 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32664339/

相关文章:

c++ - 将临时 unique_ptr 传递给 VS2010 中的构造函数

ios - 正向地理编码不适用于 CLGeocoder,但在 Apple Native Map 上按预期工作

gcc - 裸机工具链有何特别之处?

c++ - 使用范围保护时如何避免警告?

C++ 将字符串转换为 TCHAR*

iphone - 我的 Apple Dev 帐户即将过期。我的配置文件是否仍允许我在 iOS 设备上测试我的应用程序?

ios - 我可以提交不支持 4s 的 iOS 应用程序吗?

c - 从 Dcache (L1) 读取值与全局变量

c - 内联汇编代码并存储 128 位结果

c++ - operator= 的值参数导致奇怪的编译错误