Fortran DLL 新项目未在代码块中编译

Fortran DLL fresh project not compiling in Code Blocks

我刚刚在一台新 PC 上安装了 Code Blocks 13.12,并尝试创建一个 Fortran DLL 项目。我使用 MinGW 获得了代码块,因此安装了 Fortran 编译器。 如果您创建一个新的 Fortran DLL 项目,代码如下所示

! A fortran95 lib program for G95
! By WQY
subroutine sub()
    implicit none
    write(*,*) "This is subroutine"
    return
end

尽管按原样构建,但会出现以下错误:

||=== Build: Debug in FortranDLLTest (compiler: GNU GCC Compiler) ===|obj\Debug\main.o||In function `sub_':|
[...]\FortranDLLTest\main.f95|5|undefined reference to `_gfortran_st_write'|
[...]\FortranDLLTest\main.f95|5|undefined reference to `_gfortran_transfer_character_write'|
[...]\FortranDLLTest\main.f95|5|undefined reference to `_gfortran_st_write_done'|||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

这是我第一次尝试代码块,所以我没有任何线索。看起来有些东西没有链接,但一个新项目不应该直接编译吗?

您正在使用 gcc 编译您的 Fortran 代码。这很好,但你需要 link 反对 libgfortran。我不知道代码块中是如何指定的,但是您需要将 -lgfortran 添加到编译标志中。

或者,您可以使用 gfortran 作为编译器。如 here 所述,这可以通过从 "Settings" -> "Compiler..."

选择 "GNU Fortran Compiler" 来实现