c++ - 在 C++ 中使用 exit()

标签 c++ std

出于某种原因,我正在使用 C++ 中的 exit() 函数。我的 mac running lion(64 位)出现各种奇怪的错误。我正在使用 g++ -o -g -Wall 进行编译.

图表 A:

 #include <iostream>
 int main(int arc, char *argv[]){
     exit(1);
 }

终端输出如下所示

 $ g++ -o -g -Wall test main.cpp
 ld: in test, can't link with a main executable for architecture x86_64
 collect2: ld returned 1 exit status

但是$ g++ -o test main.cpp编译正常。

使用 #include<stdio.h>#include<stdlib.h>导致相同的编译错误。

我只是想知道是否有人能够立即看到这里发生了什么?

最佳答案

test 是要生成的二进制文件的名称,您的第一个参数列表应该是:

> g++ -g -Wall -o test main.cpp
               ^^^^^^^ -o has test for an argument

关于c++ - 在 C++ 中使用 exit(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8089114/

相关文章:

c++ - 模板成员函数指针

c++ - 与 const std::T 的并发

c++ - 在构造函数初始化列表中使用 std::variant

c++ - 如何通过STL容器和算法库计算两个 vector 的内积?

c++ - 通过 .def 文件在 Linux 上 Hook 函数

c++ - C/CPP 宏或预处理器来处理一个方法的多个版本

c++ - std::list,仅使用迭代器移动列表中的项目

c++ - 为什么函数accept()和recv()中地址长度参数是指针?

c++ - std::string.substr 运行时错误

c++ - 为什么 `std::sort` 会尝试比较不在输入列表中的值?