Problems calling Fortran in Windows

Hi guys,

We are trying to call a Fortan function (IGRF) from Windows. The fortan code is: https://www.ngdc.noaa.gov/IAGA/vmod/igrf12.f

(Actually many things are removed, we only need the igrf12syn function)

We are compiling using mingw and the following commands:

gfortran -c igrf12.f
gfortran -shared -fPIC igrf12.o -o igrf12.dll

Finally, we try to open the library using:

path=joinpath(pwd(),"igrf12.dll")
dl=Libdl.dlopen(path)

However, the following error appears:

could not load library "E:\01 - INPE\igrf12.dll"

dlopen(::String, ::UInt32) at libdl.jl:97
dlopen(::String) at libdl.jl:97
include_string(::String, ::String) at loading.jl:522
include_string(::String, ::String, ::Int64) at eval.jl:30
include_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N} where N) at eval.jl:34
(::Atom.##100#105{String,Int64,String})() at eval.jl:75
withpath(::Atom.##100#105{String,Int64,String}, ::String) at utils.jl:30
withpath(::Function, ::String) at eval.jl:38
hideprompt(::Atom.##99#104{String,Int64,String}) at repl.jl:66
macro expansion at eval.jl:73 [inlined]
(::Atom.##98#103{Dict{String,Any}})() at task.jl:80

We have already tried different compilers, path, etc. but we could not call this library. In Linux, it works perfectly. Can anyone help us?

We are using Windows 7 and Julia v0.6.2.

I just copied the .f file off the webpage you linked and compiled it using the same flags as above and I can confirm it is working on my Windows 10 machine w/ Julia 0.6.2.

Does Julia find it when using the find_library function?
Libdl.find_library(["libname"],["path"])

1 Like

Thanks! With your suggestion, we were able to verify that the output DLL of our Fortran compiler was 32-bits whereas Julia was 64-bits. We found a very old bug to improve the error message when this happens. Because, as of now, nothing is printed to the use.

https://github.com/JuliaLang/julia/issues/4204

Anyway, when we install Julia 32-bits, everything worked fine! Thanks one more time :smile:

Currently, a workaround is to use something like Dependencies to troubleshoot these mysterious “could not load library” errors.

1 Like