- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
is it possible to integrate an other Fortran DLL into a Fortran Code ? I didn't find information about this, only the integration of Fortan in C/C++.
is it possible to integrate an other Fortran DLL into a Fortran Code ? I didn't find information about this, only the integration of Fortan in C/C++.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The syntax of the directive is wrong. It should be:
!DEC$ ATTRIBUTES DLLIMPORT :: TEST
You should never use __imp_ in an ALIAS and the ALIAS goes before the ::.
However, since this is a routine, the DLLIMPORT directive is not required - it just adds an extra instruction or two to the call if you don't have it. The access violation is probably due to an argument mismatch, so you'll have to solve that.
!DEC$ ATTRIBUTES DLLIMPORT :: TEST
You should never use __imp_ in an ALIAS and the ALIAS goes before the ::.
However, since this is a routine, the DLLIMPORT directive is not required - it just adds an extra instruction or two to the call if you don't have it. The access violation is probably due to an argument mismatch, so you'll have to solve that.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you create the DLLNAME.DLL, a stub library is created called DLLNAME.LIB which lists all the symbols exported by that DLL (provided you included DLLEXPORT compiler directives for those routines you want to call externally from the DLL when you compile your DLL, otherwise it will be empty).
You must then include the .LIB as a file into your Fortran Executable project so that the linker can satisfy your external references to routines within the DLL. You need to make the DLLNAME.DLL available to the Fortran executable so that it is found when the executable is launched by making sure it is either within the same folder as the executable or in a folder included in your PATH environment variable.
You must then include the .LIB as a file into your Fortran Executable project so that the linker can satisfy your external references to routines within the DLL. You need to make the DLLNAME.DLL available to the Fortran executable so that it is found when the executable is launched by making sure it is either within the same folder as the executable or in a folder included in your PATH environment variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i tried to use
!DEC$ ATTRIBUTES DLLIMPORT:: Dll2 , ALIAS:"__imp__TEST" :: TEST
this works in a Test-Console-program.
But, when i compile it with Simpack
c:/SIMPACKv8.9/user/SIMPACK.8903/src/bibl/uforce/uforce21.f(288) : Info: Directive ignored - Syntax error, found ':'
when expecting one of: , ;
!DEC$ ATTRIBUTES DLLIMPORT:: Dll2, ALIAS:"__imp__TEST" :: TEST
so i find out that this should work too:
!DEC$ ATTRIBUTES DLLIMPORT:: Dll2
!DEC$ ATTRIBUTES ALIAS:"__imp__TEST" :: TEST
it is compiling, but then there is an error in the simpack.exe, which use the Dll2.dll
also in the Console is an error with the 2 line import
Hello World
forrtl: severe (157): Program Exception - access violation
Image PC Routine Line Source
Console1.exe 004B7000 Unknown Unknown Unknown
Console1.exe 004A7713 Unknown Unknown Unknown
Console1.exe 0044C857 Unknown Unknown Unknown
Console1.exe 0044C72F Unknown Unknown Unknown
kernel32.dll 76723677 Unknown Unknown Unknown
ntdll.dll 77119D42 Unknown Unknown Unknown
ntdll.dll 77119D15 Unknown Unknown Unknown
now, how can i compile, that there is no error ?
!DEC$ ATTRIBUTES DLLIMPORT:: Dll2 , ALIAS:"__imp__TEST" :: TEST
this works in a Test-Console-program.
But, when i compile it with Simpack
c:/SIMPACKv8.9/user/SIMPACK.8903/src/bibl/uforce/uforce21.f(288) : Info: Directive ignored - Syntax error, found ':'
when expecting one of: ,
!DEC$ ATTRIBUTES DLLIMPORT:: Dll2, ALIAS:"__imp__TEST" :: TEST
so i find out that this should work too:
!DEC$ ATTRIBUTES DLLIMPORT:: Dll2
!DEC$ ATTRIBUTES ALIAS:"__imp__TEST" :: TEST
it is compiling, but then there is an error in the simpack.exe, which use the Dll2.dll
also in the Console is an error with the 2 line import
Hello World
forrtl: severe (157): Program Exception - access violation
Image PC Routine Line Source
Console1.exe 004B7000 Unknown Unknown Unknown
Console1.exe 004A7713 Unknown Unknown Unknown
Console1.exe 0044C857 Unknown Unknown Unknown
Console1.exe 0044C72F Unknown Unknown Unknown
kernel32.dll 76723677 Unknown Unknown Unknown
ntdll.dll 77119D42 Unknown Unknown Unknown
ntdll.dll 77119D15 Unknown Unknown Unknown
now, how can i compile, that there is no error ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The syntax of the directive is wrong. It should be:
!DEC$ ATTRIBUTES DLLIMPORT :: TEST
You should never use __imp_ in an ALIAS and the ALIAS goes before the ::.
However, since this is a routine, the DLLIMPORT directive is not required - it just adds an extra instruction or two to the call if you don't have it. The access violation is probably due to an argument mismatch, so you'll have to solve that.
!DEC$ ATTRIBUTES DLLIMPORT :: TEST
You should never use __imp_ in an ALIAS and the ALIAS goes before the ::.
However, since this is a routine, the DLLIMPORT directive is not required - it just adds an extra instruction or two to the call if you don't have it. The access violation is probably due to an argument mismatch, so you'll have to solve that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the TEST-dll looks at the moment
subroutine TEST()
!dec$ attributes dllexport :: TEST
implicit none
write(*, '(A)', advance='YES') "Hallo"
write(*, '(A)', advance='YES') "Welt"
write(*, *) "ABCDEFGHIJKLMN"
return
end subroutine TEST
and without the dllimport i can't use it.
ERROR: uforce21.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol "_test@0" in Funktion "_uforce21".
ERROR: C:\\SIMPACKv8.9\\user\\SIMPACK.8903\\lib\\win32\\libuser_o.dll : fatal error LNK1120: 1 nicht aufgelste externe Verweise.
subroutine TEST()
!dec$ attributes dllexport :: TEST
implicit none
write(*, '(A)', advance='YES') "Hallo"
write(*, '(A)', advance='YES') "Welt"
write(*, *) "ABCDEFGHIJKLMN"
return
end subroutine TEST
and without the dllimport i can't use it.
ERROR: uforce21.obj : error LNK2019: Verweis auf nicht aufgelstes externes Symbol "_test@0" in Funktion "_uforce21".
ERROR: C:\\SIMPACKv8.9\\user\\SIMPACK.8903\\lib\\win32\\libuser_o.dll : fatal error LNK1120: 1 nicht aufgelste externe Verweise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Clearly, you have forgotten to add DLL2.LIB to your console project, becuase the external reference to _TEST@0 has not been satisfied. SO make sure to add DLL2.LIB and rebuild your console project, then make sure that DLL2.DLL is added to the folder containing your console executable, then all should work.
For example:
This is the DLL code:
subroutine TEST()
! Expose subroutine test to users of this DLL
!dec$ attributes dllexport :: TEST
implicit none
write(*, '(A)', advance='YES') "Hallo"
write(*, '(A)', advance='YES') "Welt"
write(*, *) "ABCDEFGHIJKLMN"
return
end subroutine TEST
and this is the console program code:
program consoledlltest
!DEC$ ATTRIBUTES DLLIMPORT :: TEST
implicit none
print *, 'Hello World'
call test()
end program consoledlltest
which builds and runs fine when the DLL's stub library .LIB is added to the console project. The successful output is attached. You can always find out what symbols have been EXPORTed from your DLL by using the DUMPBIN tool that comes with Visual Studio as shown in the other attached picture.
For example:
This is the DLL code:
subroutine TEST()
! Expose subroutine test to users of this DLL
!dec$ attributes dllexport :: TEST
implicit none
write(*, '(A)', advance='YES') "Hallo"
write(*, '(A)', advance='YES') "Welt"
write(*, *) "ABCDEFGHIJKLMN"
return
end subroutine TEST
and this is the console program code:
program consoledlltest
!DEC$ ATTRIBUTES DLLIMPORT :: TEST
implicit none
print *, 'Hello World'
call test()
end program consoledlltest
which builds and runs fine when the DLL's stub library .LIB is added to the console project. The successful output is attached. You can always find out what symbols have been EXPORTed from your DLL by using the DUMPBIN tool that comes with Visual Studio as shown in the other attached picture.

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