- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm using modules for some time now and want to build them as a dll.
While doing so I find a problem when running my main program.
The file that is opened in a subroutine that is in the module which is build as a dll cannot be read in the main program. In the module I can read from the file without any problems.
My main program:
PROGRAM main
USE m_fileutils
INTEGER :: err
CHARACTER(LEN=255) :: line ! line to read
!
! Open the file for reading, using a subroutine contained in a module build as dll.
!
CALL sysopen_read(599,"inputfile",err)
READ (599, '(a)') line
WRITE (6,*) line
END
The code of the subroutine in the module build as dll:
MODULE m_fileutils
IMPLICIT NONE
CONTAINS
!-------------------------------------------------------------------------------------------------------------------------------
! SUBROUTINE: sysopen_read
! PURPOSE : Opening of text file for reading.
!-------------------------------------------------------------------------------------------------------------------------------
SUBROUTINE sysopen_read(iu, fnam, io_status)
!DEC$ ATTRIBUTES DLLEXPORT:: sysopen_read
INTEGER*4, INTENT(IN) :: iu !
CHARACTER*(*), INTENT(IN) :: fnam !
INTEGER*4, INTENT(OUT) :: io_status ! Status of I/O action
INTEGER*4 :: flen ! Length of filename
CHARACTER(LEN=255) :: line
!-------------------------------------------------------------------------------------------------------------------------------
flen = LEN_TRIM(fnam)
OPEN (iu, FILE=fnam(1:flen), IOSTAT=io_status)
WRITE(6,*) " Opened file : ", fnam(1:flen)
!
! Just read and write some lines from the file
!
READ (iu, '(a)') line
WRITE (6,*) line
READ (iu, '(a)') line
WRITE (6,*) line
REWIND(iu)
RETURN
END SUBROUTINE sysopen_read
!-------------------------------------------------------------------------------------------------------------------------------
END MODULE m_fileutils
Compiling and linking without any warnings or error message:
The output of the program:
D:\\projects\\test_dll\\main\\Release>main
Opened file : inputfile
Line number 1 of file "inputfile"
Line number 2 of file "inputfile"
forrtl: severe (29): file not found, unit 599, file D:\\projects\\test_dll\\main\\Release\\fort.599
Image PC Routine Line Source
main.exe 0045BE9A Unknown Unknown Unknown
main.exe 00459729 Unknown Unknown Unknown
main.exe 0040FECB Unknown Unknown Unknown
main.exe 0040F08B Unknown Unknown Unknown
main.exe 00403114 Unknown Unknown Unknown
main.exe 00401081 Unknown Unknown Unknown
main.exe 00461E43 Unknown Unknown Unknown
main.exe 00447344 Unknown Unknown Unknown
kernel32.dll 7C817077 Unknown Unknown Unknown
D:\\projects\\test_dll\\main\\Release>
The contents of the file "inputfile":
Line number 1 of file "inputfile"
Line number 2 of file "inputfile"
Line number 3 of file "inputfile"
Line number 4 of file "inputfile"
Whenever, while building the main program, I link the file m_fileutils.obj instead of the dll in which the object is it all works fine.
Should I be aware of some options/ properties I have to use while building the dll?
Any help appreciated,
Kind regards,
Wilco de vries.
I'm using modules for some time now and want to build them as a dll.
While doing so I find a problem when running my main program.
The file that is opened in a subroutine that is in the module which is build as a dll cannot be read in the main program. In the module I can read from the file without any problems.
My main program:
PROGRAM main
USE m_fileutils
INTEGER :: err
CHARACTER(LEN=255) :: line ! line to read
!
! Open the file for reading, using a subroutine contained in a module build as dll.
!
CALL sysopen_read(599,"inputfile",err)
READ (599, '(a)') line
WRITE (6,*) line
END
The code of the subroutine in the module build as dll:
MODULE m_fileutils
IMPLICIT NONE
CONTAINS
!-------------------------------------------------------------------------------------------------------------------------------
! SUBROUTINE: sysopen_read
! PURPOSE : Opening of text file for reading.
!-------------------------------------------------------------------------------------------------------------------------------
SUBROUTINE sysopen_read(iu, fnam, io_status)
!DEC$ ATTRIBUTES DLLEXPORT:: sysopen_read
INTEGER*4, INTENT(IN) :: iu !
CHARACTER*(*), INTENT(IN) :: fnam !
INTEGER*4, INTENT(OUT) :: io_status ! Status of I/O action
INTEGER*4 :: flen ! Length of filename
CHARACTER(LEN=255) :: line
!-------------------------------------------------------------------------------------------------------------------------------
flen = LEN_TRIM(fnam)
OPEN (iu, FILE=fnam(1:flen), IOSTAT=io_status)
WRITE(6,*) " Opened file : ", fnam(1:flen)
!
! Just read and write some lines from the file
!
READ (iu, '(a)') line
WRITE (6,*) line
READ (iu, '(a)') line
WRITE (6,*) line
REWIND(iu)
RETURN
END SUBROUTINE sysopen_read
!-------------------------------------------------------------------------------------------------------------------------------
END MODULE m_fileutils
Compiling and linking without any warnings or error message:
The output of the program:
D:\\projects\\test_dll\\main\\Release>main
Opened file : inputfile
Line number 1 of file "inputfile"
Line number 2 of file "inputfile"
forrtl: severe (29): file not found, unit 599, file D:\\projects\\test_dll\\main\\Release\\fort.599
Image PC Routine Line Source
main.exe 0045BE9A Unknown Unknown Unknown
main.exe 00459729 Unknown Unknown Unknown
main.exe 0040FECB Unknown Unknown Unknown
main.exe 0040F08B Unknown Unknown Unknown
main.exe 00403114 Unknown Unknown Unknown
main.exe 00401081 Unknown Unknown Unknown
main.exe 00461E43 Unknown Unknown Unknown
main.exe 00447344 Unknown Unknown Unknown
kernel32.dll 7C817077 Unknown Unknown Unknown
D:\\projects\\test_dll\\main\\Release>
The contents of the file "inputfile":
Line number 1 of file "inputfile"
Line number 2 of file "inputfile"
Line number 3 of file "inputfile"
Line number 4 of file "inputfile"
Whenever, while building the main program, I link the file m_fileutils.obj instead of the dll in which the object is it all works fine.
Should I be aware of some options/ properties I have to use while building the dll?
Any help appreciated,
Kind regards,
Wilco de vries.
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The thing to be aware of is when building the executable. A DLL project, by default, links to the DLL form of the run-time libraries, but an executable project, by default, links to static libraries. This means you get two copies of the libraries that don't know about the other.
Solution is to change the executable project property Fortran > Libraries > Use Run-time library to "Multithreaded DLL" (matching what your DLL project uses.) Be aware of the difference between Debug and Release configurations.
Solution is to change the executable project property Fortran > Libraries > Use Run-time library to "Multithreaded DLL" (matching what your DLL project uses.) Be aware of the difference between Debug and Release configurations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
Thanks for the answer.
But, whenever I build the executable using "Multithreaded DLL" it starts complaining about missing libifcoremb.dll when I run it. Of course I can expand my PATH variable so it can be found, but how does this work on a computer where these dll's are not installed? And I don't know what other dll's are needed.
That's the reason why I fisrt compiled using /libs:static
Regards, Wilco.
Thanks for the answer.
But, whenever I build the executable using "Multithreaded DLL" it starts complaining about missing libifcoremb.dll when I run it. Of course I can expand my PATH variable so it can be found, but how does this work on a computer where these dll's are not installed? And I don't know what other dll's are needed.
That's the reason why I fisrt compiled using /libs:static
Regards, Wilco.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you're going to use a Fortran DLL called from a Fortran executable, you have no choice - you must link to the DLL libraries for correct operation. We provide free redistributable installers for systems that don't have the compiler installed. Be sure to build a Release configuration for this. See here for more info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
Thanks again for your answer.
I build the executable and we are going to test it now.
Regards, Wilco.
Thanks again for your answer.
I build the executable and we are going to test it now.
Regards, Wilco.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
The results of the test are all ok.
Now I'm trying to find out how I can add a versionnumber or something like that to the dll? And a tool to check it out so our customers are sure to have the latest version.
I filled out a number in the "version" field. In the file buildlog.html I do find this number but I don't know how to get in in the dll (Well maybe it is in now and I only have to get it out?).
The windows tool "filever" does not give back this information.
Regards, Wilco.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do this by adding a "version resource" that is then compiled with the resource compiler. Right click on the project, add a new item. Select Resource File. When the resource editor opens, right click on the top of the "tree" in the resource editor, select Add Resource, then Version. The "File Version" is the most important item. You can also edit a copyright string.
Note that if you are using the Visual Studio Shell, you don't have the resource editor. If you're in that situation, there are some alternatives.
Note that if you are using the Visual Studio Shell, you don't have the resource editor. If you're in that situation, there are some alternatives.

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