2016-01-20 116 views
1

執行以下操作時,失敗編譯的退出代碼爲1,但根據this,我預計它會大於等於3。爲什麼是這樣?如果我想要比二進制成功/失敗更詳細的退出代碼,我該怎麼辦?在g ++中使用-pass退出代碼時發生意外退出狀態

> echo "int main() {fail}" > fail.cpp 
> g++ -pass-exit-codes fail.cpp -o fail 
fail.cpp: In function ‘int main()’: 
fail.cpp:1: error: ‘fail’ was not declared in this scope 
fail.cpp:1: error: expected ';' before ‘}’ token 
> echo $? 
1 
> g++ --version 
g++ (GCC) 4.1.3 20080704 (Red Hat 4.1.2-27) 

謝謝。

回答

0

您指出的文檔屬於gcc版本3.3.6。然而,在版本> = 4,對於編譯器標誌的文件已經改變,現在只是指出:

-pass-exit-codes
Normally the gcc program exits with the code of 1 if any phase of the compiler returns a non-success return code. If you specify -pass-exit-codes, the gcc program instead returns with the numerically highest error produced by any phase returning an error indication. The C, C++, and Fortran front ends return 4 if an internal compiler error is encountered.

讀書時,這是一個有點混亂。它沒有指定在3.x文檔中詳細解釋的錯誤代碼。然後,您可能正在尋找的退出代碼在gcc/g ++的4.x版本中不再生成。

+0

有道理。然後問題是版本> = 4的退出代碼是什麼?沒有在任何地方找到它們,也無法想出激發1以外的退出代碼的方式(我認爲它必須表示「源文件無法編譯」)。 – user1622959

+0

不幸的是,除了退出代碼4(內部編譯器錯誤),似乎沒有文檔。如果你遵循gcc 4.8.2源代碼(在gcc/system.h)中定義的錯誤代碼(和覆蓋),唯一定義的是0,1和4,所以我想這就是它。 –

+0

我正在尋找區分內部g ++錯誤與源代碼錯誤,特別是,我需要確定以下錯誤:'fatal_error(input_location,「必須重新定位PCH」);'(gcc/gcc-common.c)。根據我對代碼的快速瀏覽,'fatal'會是1的退出碼,這是正確的嗎? – user1622959