Emacs gfortran编译异常退出,代码为1

Emacs gfortran编译异常退出,代码为1,emacs,compiler-errors,mingw,Emacs,Compiler Errors,Mingw,我正在尝试使用gfortran编译一个简单的Fortran hello world脚本。它可以在Windows控制台中很好地编译,但不能在Emacs中编译。这与它的环境有关吗?我没有使用任何库。如果您能帮助我们理解原因,我们将不胜感激 简单的“你好,世界”: 下面是compile命令,使用M-x compile: C:\MinGW\bin\gfortran.exe C:\emacs\fortran\hello.f -o C:\emacs\fortran\hello.exe Emacs报告此错误

我正在尝试使用gfortran编译一个简单的Fortran hello world脚本。它可以在Windows控制台中很好地编译,但不能在Emacs中编译。这与它的环境有关吗?我没有使用任何库。如果您能帮助我们理解原因,我们将不胜感激

简单的“你好,世界”:

下面是compile命令,使用M-x compile:

C:\MinGW\bin\gfortran.exe C:\emacs\fortran\hello.f -o C:\emacs\fortran\hello.exe
Emacs报告此错误:

Compilation exited abnormally with code 1 at Fri May 10 18:10:15

谢谢,

为了简化编译命令,您可以将
gfortran
的路径添加到
exec路径中,这样就可以找到编译器(使用
测试(可执行文件查找“gfortran”)

(cl pushnew“path/to/mingw/bin”执行路径:test#'equal)

您还可以在
fortran模式挂钩
中设置默认的
compile命令
,例如,要使用一些默认标志(针对windows修改)编译当前文件,您可以使用以下命令:

(add-hook 'fortran-mode-hook #'my-fortran-hook)

(defun my-fortran-hook ()
  (setq-local
   compile-command
   (format "gfortran -Wall -Wextra -fbounds-check -g -std=f95 -Ofast -o %s %s"
           (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
           (buffer-file-name))))

为了简化编译命令,您可以将
gfortran
的路径添加到
exec路径中,该路径应允许找到编译器(使用
测试(可执行文件查找“gfortran”)

(cl pushnew“path/to/mingw/bin”执行路径:test#'equal)

您还可以在
fortran模式挂钩
中设置默认的
compile命令
,例如,要使用一些默认标志(针对windows修改)编译当前文件,您可以使用以下命令:

(add-hook 'fortran-mode-hook #'my-fortran-hook)

(defun my-fortran-hook ()
  (setq-local
   compile-command
   (format "gfortran -Wall -Wextra -fbounds-check -g -std=f95 -Ofast -o %s %s"
           (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
           (buffer-file-name))))

谢谢!快速更新-当我导航到编译器以使其成为当前目录时,它确实起作用。如果我在另一个文件夹中编辑脚本,除非我为编译器使用不同的缓冲区,否则会有点麻烦。是的,m-x compile,然后选择要在compile命令中运行的编译器,如描述中所示。谢谢!快速更新-它起作用了当我导航到编译器以使其成为当前目录时。如果我在另一个文件夹中编辑脚本,除非我为编译器使用不同的缓冲区,否则会有点麻烦。是的,m-x compile,然后选择要在compile命令中运行的编译器,如描述中所示。谢谢,这很完美,但是当我尝试使用(cl pushnew exec path“C:/MinGW/bin”:test#'equal)它给我一个错误,说“%S不是有效的位置表达式:C:/MinGW/bin”谢谢,这很完美,但当我尝试使用(cl pushnew exec path“C:/MinGW/bin”:test#'equal)时,它给我一个错误,说“%S不是有效的位置表达式:C:/MinGW/bin”