Steak Overflow
Steak Overflow

Reputation: 7618

Fortran DLL fresh project not compiling in Code Blocks

I just freshly installed Code Blocks 13.12 in a new PC and tried creating a Fortran DLL project. I got Code Blocks with MinGW so Fortran compiler is installed. If you create a new Fortran DLL project the code looks like this

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

When you build though, as it is, you'll get the following errors:

||=== 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)) ===|

It's the first time I try in Code Blocks so I have no clues. Looks like something isn't linked but shouldn't a new project just compile straight away?

Upvotes: 0

Views: 714

Answers (1)

Alexander Vogt
Alexander Vogt

Reputation: 18098

You are using gcc to compile your Fortran code. This is fine, but you need to link against libgfortran. I do not know how this is specified in Code Blocks, but you need to add -lgfortran to the compile flags.

Alternatively, you could use gfortran as a compiler instead. As described here, this can be achieved by choosing "GNU Fortran Compiler" from "Settings" -> "Compiler..."

Upvotes: 2

Related Questions