When I call a function from fortran complied dll in windows, there is a "EXCEPTION_ACCESS_VIOLATION" error

The julia version:

(base) D:\julia_code_w\WEM3D\WEM3D\test\Fwd0114>julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.    
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.7 (2022-07-19)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release  
|__/                   |

julia> versioninfo()
Julia Version 1.6.7
Commit 3b76b25b64 (2022-07-19 15:11 UTC)  
Platform Info:
  OS: Windows (x86_64-w64-mingw32)        
  CPU: 12th Gen Intel(R) Core(TM) i5-1240P
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, goldmont)
Environment:
  JULIA_PKG_SERVER = https://mirrors.ustc.edu.cn/julia
  • We packaged a frotran code to a dll file in windows platform using the mingw64, if we solely use the package, the code runs successfully as follows:
(base) D:\julia_code_w\WEM3D\EM1DUtils\test>julia testDipole1d.jl
Computing 1D response E field...
D:\julia_code_w\WEM3D\EM1DUtils\lib\Dipole1D
Computing 1D response E specifically ...
D:\julia_code_w\WEM3D\EM1DUtils\lib\Dipole1D
line 98
  0.013006 seconds (14.49 k allocations: 834.653 KiB, 60.82% compilation time)
 Computing 1D response for finite-dipole ...
=== All functions in dipole1D passed ===
  • And if we use this package from other package, there will be the following message:
julia setupParaFwd.jl
Reading data file D:\julia_code_w\WEM3D\WEM3D\test\Fwd0114\wem3dFwdTest0312.dat ...
  0.003353 seconds (1.68 k allocations: 197.875 KiB)
Reading model file D:\julia_code_w\WEM3D\WEM3D\test\Fwd0114\wemFwdtest0312.model ...
  3.118062 seconds (4.01 M allocations: 237.850 MiB, 3.85% gc time, 78.76% compilation time)
Forming discretized operators ...
  1.639375 seconds (2.66 M allocations: 1.620 GiB, 21.94% gc time, 61.54% compilation time)
Computing receiver term ...
  1.449448 seconds (4.24 M allocations: 252.700 MiB, 2.85% gc time, 65.79% compilation time)
Setting up reference model ...
Calculating primary electric fields ...
D:\julia_code_w\WEM3D\EM1DUtils\lib\Dipole1D
line 98

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x5e2f3470 -- calldipole1deb_ at D:\julia_code_w\WEM3D\EM1DUtils\lib\Dipole1D.DLL (unknown line)
in expression starting at D:\julia_code_w\WEM3D\WEM3D\test\Fwd0114\setupParaFwd.jl:62
calldipole1deb_ at D:\julia_code_w\WEM3D\EM1DUtils\lib\Dipole1D.DLL (unknown line)
comp1DCSEM at D:\julia_code_w\WEM3D\EM1DUtils\src\dipole1D.jl:99
macro expansion at .\timing.jl:210 [inlined]
compPrimaryElectricField at D:\julia_code_w\WEM3D\WEM3D\src\CSEMFwdSolver\compAnalyticField.jl:188
unknown function (ip: 00000000567d6a42)
compPrimaryElectricField at D:\julia_code_w\WEM3D\WEM3D\src\CSEMFwdSolver\compAnalyticField.jl:255
top-level scope at .\timing.jl:287
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:871
jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:825
jl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:886 [inlined]
jl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:929
eval at .\boot.jl:360 [inlined]
include_string at .\loading.jl:1116
_include at .\loading.jl:1170
include at .\Base.jl:384
exec_options at .\client.jl:285
_start at .\client.jl:485
jfptr__start_28700.clone_1 at C:\Users\acer\AppData\Local\Programs\Julia-1.6.7\lib\julia\sys.dll (unknown line)
jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined]
true_main at /cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:560
repl_entrypoint at /cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:702
mainCRTStartup at /cygdrive/c/buildbot/worker/package_win64/build/cli\loader_exe.c:51
BaseThreadInitThunk at C:\Windows\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
Allocations: 14127831 (Pool: 14118721; Big: 9110); GC: 18
  • And I have tried the julia version 1.6, 1.7, 1.8, 1.9, all these versions display the previous message. Could you help me to solve it?
  • It can run successfully in Ubuntu platform using the same gfortran compiler.