簡體   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