简体   繁体   中英

Using exit() in c++

For one reason or another, I am messing around with the exit() function in c++. I am getting all kinds of strange errors from my mac running lion (64 bit). I am compiling using g++ -o -g -Wall .

Exhibit 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.

using #include<stdio.h> or #include<stdlib.h> result in the same compilation error.

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:

> 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. It is probably trying to use your old binary 'test' as a source file, incorrectly.

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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