- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Calling this routine worked fine when my main program was compiled using ifort. However, if I compile my main program with ifx, the subroutine fails, and either gets stuck in an infinite loop or completely crashes. Since it is basically a black box dll file, I don’t have access to any diagnostics or anything to figure out why or where it is breaking. My best guess is that it’s an issue with data types or variable initialization: the only error it does give is “The value of integer variable X should be 1 or 2. The current value is -856384859087.”
Does anyone have any insights on what could cause this, or what steps I can take to troubleshoot it? A snippet of my code is below:
‘’’
Program Main
Implicit None
#include Globals.cmn
Integer X,Y,Z
Real*8 Val1, Val2
Parameter (X = 1, Y=3, Z = 7)
Val1 = 23.2
Call Calcs(X,Y,Z,Val1,Val2)
Write(*,*) Val2, GVAR56
End program main
‘’’
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I might guess that it's related to this issue from the Release Notes:
BLOCK DATA
- On Windows systems, a subprogram built into a library that references a common block variable initialized in a BLOCK DATA subprogram that is compiled separately and linked with the library will not get initialized but will have a zero value. The workaround for this problem is to compile the subprogram and the BLOCK DATA subprogram together, or pass the object file with BLOCK DATA separately on the link line.
but I'm having difficulty trying to see how this combines with a DLL. Does your include file declare the common blocks with ATTRIBUTES DLLIMPORT? This is required if accessing common blocks from a DLL.
I'm going to put together a small test and see if I can reproduce a problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes - all of them do include !DIR$ ATTRIBUTES DLLIMPORT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, I built a test case that imported a common block from a DLL and it worked. I reproduce it below. Your DLL's code must have been touched since the 60s as if it requires sharing a common block from a DLL then source changes not created until the late 90s would be required.
dll1.f90
subroutine foo
implicit none
!DIR$ ATTRIBUTES DLLEXPORT :: foo
character(4) :: cx
common /cmn/ cx
!DIR$ ATTRIBUTES DLLEXPORT :: /cmn/
print '(A,1X,Z16)', "In Foo, LOC(cx) is ", LOC(cx)
print *, cx
return
end
block data
integer :: cx
common /cmn/ cx
data cx /'FAIL'/
end block data
console1.f90
program Console1
implicit none
character(4) :: cx
common /cmn/ cx
!DIR$ ATTRIBUTES DLLIMPORT :: /cmn/
external :: foo
!DIR$ ATTRIBUTES DLLIMPORT :: foo
cx = 'PASS'
print '(A,1X,Z16)', "In Main, LOC(cx) is", LOC(cx)
call foo
end program Console1
Build and run:
D:\Projects\Dll1\Console1>ifx /dll dll1.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.43.34809.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:dll1.dll
-dll
-implib:dll1.lib
dll1.obj
Creating library dll1.lib and object dll1.exp
D:\Projects\Dll1\Console1>ifx console1.f90 dll1.lib
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.43.34809.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:console1.exe
-subsystem:console
console1.obj
dll1.lib
D:\Projects\Dll1\Console1>console1.exe
In Main, LOC(cx) is 7FF874E83000
In Foo, LOC(cx) is 7FF874E83000
PASS
D:\Projects\Dll1\Console1>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe a naive question but is your DLL 32bit or 64bit? IFX is producing only 64 bit code, what did your IFORT setup generate?
Given there are no interfaces specified your are passing to Calcs by reference i.e. passing 64bit addresses.....

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page