Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Problem with exporting subroutine to DLL

Jon_R_
Beginner
576 Views

Hi!

I have a problem when exporting code to DLL using the  DLLEXPORT markup. This is compiler version XE 4.0.0.103 on IA-32. I. My main subroutine that I want other applications to be able to access is called subroutine User_Mod(...). I write:

!DEC$ ATTRIBUTES DLLEXPORT,StdCall,Reference,ALIAS:"User_Mod" :: User_Mod                   (1)

However, this gives an error from the compiler:

usrmod.obj : error LNK2019: unresolved external symbol _USER_MOD referenced in function _CLASS_LABTEST_mp_RESULTTABLE.
usrmod.dll : fatal error LNK1120: 1 unresolved externals

(the reason is because the subroutine User_Mod is called elsewhere in the exported code). If I then try to change the export line to:

!DEC$ ATTRIBUTES DLLEXPORT,StdCall,Reference,ALIAS:"User_Mod" :: _User_Mod  (i.e. with underscore)              (2)

the code compiles and a dll is created which is great. However  the  external program that will be using the DLL does not recognize it, so the DLL export will have to be written as in (1). The code works well if I generate an executable, however I am unsure how to solve this problem with underscore.  . Any help or prior experience regarding this would be greatly appreciated.

Thanks.

Jon

0 Kudos
2 Replies
Jon_R_
Beginner
576 Views

I found a way around the problem. It was to create a dummy subroutine called User_Mod which then calls the subroutine which I originally wanted to use, i.e.:

subroutine User_Mod (...)
  !DEC$ ATTRIBUTES DLLEXPORT,StdCall,Reference :: User_Mod 
  !Dummy subroutine

  ! Actual subroutine
  
call User_Mod2(...)

end subroutine

0 Kudos
IanH
Honored Contributor III
576 Views

Providing an interface body for User_Mod at the point of the problematic call was another option.

0 Kudos
Reply