简体   繁体   English

在C ++中使用exit()

[英]Using exit() in c++

For one reason or another, I am messing around with the exit() function in c++. 由于一个或另一个原因,我在使用c ++中的exit()函数。 I am getting all kinds of strange errors from my mac running lion (64 bit). 我从运行Mac的狮子(64位)中收到各种奇怪的错误。 I am compiling using g++ -o -g -Wall . 我正在使用g++ -o -g -Wall编译。

Exhibit A: 展览A:

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

The Terminal output looks like this 终端输出看起来像这样

 $ 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

but $ g++ -o test main.cpp compiles fine. 但是$ g++ -o test main.cpp编译。

using #include<stdio.h> or #include<stdlib.h> result in the same compilation error. 使用#include<stdio.h>#include<stdlib.h>导致相同的编译错误。

I am just wondering if anyone might be able to see immediately what is going on here? 我只是想知道是否有人可以立即看到这里发生了什么?

test is the name of the binary to produce, your first argument list should be: test是要生成的二进制文件的名称,您的第一个参数列表应为:

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

-o is meant to be followed immediately by the name of the output file. -o的意思是紧随其后的是输出文件的名称。 It is probably trying to use your old binary 'test' as a source file, incorrectly. 可能是试图错误地将您的旧二进制“测试”用作源文件。

Try this: 尝试这个:

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

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

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