繁体   English   中英

在C ++中使用exit()

[英]Using exit() in c++

由于一个或另一个原因,我在使用c ++中的exit()函数。 我从运行Mac的狮子(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

-o的意思是紧随其后的是输出文件的名称。 可能是试图错误地将您的旧二进制“测试”用作源文件。

尝试这个:

g++ -o test -g -Wall main.cpp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM