隐藏gfortran运行时错误消息中的完整路径

时间:2012-06-12 03:52:04

标签: fortran gfortran

我正在使用gfortran编写一个包含十几个模块的大程序。只要代码中出现错误,程序就会生成一条错误消息,其中包含发生错误的行号和该行所属模块的完整路径。例如:

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

我的问题是如何阻止程序列出违规模块的完整路径,而是让它只报告发生错误的模块名称。

1 个答案:

答案 0 :(得分: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

将编译命令更改为仅使用相对路径访问源。

相关问题