2012-06-12 45 views
0

我正在使用gfortran編譯一個包含十幾個模塊的大程序。只要代碼有錯,程序就會生成一條錯誤消息,其中包含發生錯誤的行號和該行所屬模塊的完整路徑。例如:隱藏gfortran運行時錯誤消息的完整路徑

At line 1775 of file C:\temp\test.f90 (Unit = 200, file=' ') 
Fortran Run time error: File '*' does not exist 

我的問題是你怎麼從上市違規模塊的完整路徑,停止程序和相當使它只報告在錯誤發生的模塊名稱。

回答

1

gfortran嵌入在編譯階段用於訪問源文件的路徑。例如。如果使用該文件的完整路徑進行編譯,則將在調試輸出中獲得完整路徑。如果使用相對路徑進行編譯,則將在輸出中獲得相對路徑:

~/tests[520]$ gfortran -o test.x test.f90 
~/tests[521]$ test.x 
At line 3 of file test.f90 (unit = 200, file = '') 
Fortran runtime error: File '' does not exist 

~/tests[522]$ gfortran -o test.x ./test.f90 
~/tests[523]$ test.x 
At line 3 of file ./test.f90 (unit = 200, file = '') 
Fortran runtime error: File '' does not exist 

~/tests[524]$ gfortran -o test.x ~/tests/test.f90 
~/tests[525]$ test.x 
At line 3 of file /home/username/tests/test.f90 (unit = 200, file = '') 
Fortran runtime error: File '' does not exist 

將編譯命令更改爲僅使用相對路徑訪問源。

+0

感謝Hristo,但我的程序是用Cmake編譯的,我沒有明確告訴gfortran我的源文件的位置。相反,我將源文件夾和bin文件夾輸入到Cmake GUI中。源文件是輸入到Cmakelist.txt文件中的信息的一部分。我不知道在CMake GUI中是否有一個選項可以設置爲使其通過相對路徑而不是完整路徑。 謝謝 Abdinasir –

+0

對不起,我從來沒有使用Cmake GUI(甚至不知道它存在到現在)。 –