# Problems calling Fortran in Windows

**URL:** https://discourse.julialang.org/t/problems-calling-fortran-in-windows/10271
**Category:** General Usage
**Created:** [April 11, 2018, 1:21am UTC](https://discourse.julialang.org/t/problems-calling-fortran-in-windows/10271 "2018-04-11T01:21:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [April 11, 2018, 1:21am UTC](https://discourse.julialang.org/t/problems-calling-fortran-in-windows/10271/1 "2018-04-11T01:21:08Z")

</div>

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](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:

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

```

Finally, we try to open the library using:

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

```

However, the following error appears:

```julia
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.

---

<div class="post-metadata">

### Author: ![Crghilardi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crghilardi/32/3738_2.png) [@Crghilardi](https://discourse.julialang.org/u/Crghilardi)
#### Post date: [April 11, 2018, 2:09am UTC](https://discourse.julialang.org/t/problems-calling-fortran-in-windows/10271/2 "2018-04-11T02:09:56Z")

</div>

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](https://docs.julialang.org/en/stable/stdlib/libdl/#Base.Libdl.find_library) function?  
`Libdl.find_library(["libname"],["path"])`

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [April 11, 2018, 12:45pm UTC](https://discourse.julialang.org/t/problems-calling-fortran-in-windows/10271/3 "2018-04-11T12:45:14Z")

</div>

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](https://github.com/JuliaLang/julia/issues/4204)

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

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [April 11, 2018, 12:59pm UTC](https://discourse.julialang.org/t/problems-calling-fortran-in-windows/10271/4 "2018-04-11T12:59:24Z")

</div>

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

> **[GitHub - lucasg/Dependencies: A rewrite of the old legacy software...](https://github.com/lucasg/Dependencies)**
>
> A rewrite of the old legacy software "depends.exe" in C# for Windows devs to troubleshoot dll load dependencies issues. - GitHub - lucasg/Dependencies: A rewrite of the old legacy softwar...
