Dynamic Link Library, Compaq Visual Fortran 6.6 & Module

In summary, the user is seeking help with creating a dynamic-link library (DLL) for a Fortran application using Compaq Visual Fortran 6.6. They have successfully created a DLL with a working code, but when implementing the same algorithm using a module, the result is incorrect. They have built the DLL and LIB files from the visual development environment and are looking for advice on how to resolve this issue.
  • #1
Bakhbergen
3
1
Dear Forum Members,
I need to create and use dynamic-link library (DLL) for Fortran application using Compaq Visual Fortran 6.6. The following code works just fine:

###########################################
PROGRAM AMAIN1
IMPLICIT NONE
REAL(8):: A,B,S
A = 1D0
B = 2D0
CALL SUBRO1(A,B,S)
PRINT*, 'S = ', S
END PROGRAM AMAIN1
###########################################
SUBROUTINE SUBRO1(A,B,S)
!DEC$ ATTRIBUTES DLLEXPORT :: SUBRO1
IMPLICIT NONE
REAL(8):: A,B,S
S = A + B
RETURN
END SUBROUTINE SUBRO1
###########################################
The result is correct:
S = 3.00000000000000
Press any key to continue
###########################################

However, if I implement the same algorithm using the module, I get inconsistent result (i.e. zero):

###########################################
PROGRAM AMAIN2
USE MODUL2
IMPLICIT NONE
A = 1D0
B = 2D0
CALL SUBRO2
PRINT*, 'S = ', S
END PROGRAM AMAIN2
###########################################
MODULE MODUL2
IMPLICIT NONE
REAL(8):: A,B,S
END MODULE MODUL2
###########################################
SUBROUTINE SUBRO2
!DEC$ ATTRIBUTES DLLEXPORT :: SUBRO2
USE MODUL2
IMPLICIT NONE
S = A + B
RETURN
END SUBROUTINE SUBRO2
###########################################
The result is incorrect:
S = 0.000000000000000E+000
Press any key to continue
###########################################

As can be seen above, DLL contains only subprogram in both cases (SUBRO1 and SUBRO2, respectively). I have built DLL and LIB files from the visual development environment. The second case (with the use of module) represents the structure of my large source-code so I need to resolve this issue. Any advice would be greatly appreciated.
 
Physics news on Phys.org
  • #2
Hallo Bakhbergen, ##\qquad## :welcome:

Modul2 is only a declaration of local variables. You need something like COMMON to make them global is what I would suspect.

(old hand, more fortran 77 than f90, but who knows this helps)
 
  • Like
Likes Bakhbergen
  • #3
  • Like
Likes Bakhbergen
  • #4
BvU said:
However, https://www.tutorialspoint.com/fortran/fortran_modules.htm claims global character.
Your result does not reflect that. Still worth investigating (ask for the addresses of the variables in debug or something ?)

Hello BvU! I appreciate your intention to help with this. There weren't any error / warning during the debugging. Just gives incorrect result.
 
  • #5
I don't expect any errors reported, just diffferent address spaces assigned in the DLL and the main EXE
 
  • Like
Likes Bakhbergen
  • #6
BTW, the same algorithm without using the DLL works well and gives correct result:

PROGRAM AMAIN3
USE MODUL3
IMPLICIT NONE
A = 1D0
B = 2D0
CALL SUBRO3
PRINT*, 'S = ', S
END PROGRAM AMAIN3

MODULE MODUL3
IMPLICIT NONE
REAL(8):: A,B,S
END MODULE MODUL3

SUBROUTINE SUBRO3
USE MODUL3
IMPLICIT NONE
S = A + B
RETURN
END SUBROUTINE SUBRO3

S = 3.00000000000000
Press any key to continue
 

1. What is a Dynamic Link Library (DLL)?

A Dynamic Link Library (DLL) is a collection of small programs that can be loaded and used by different applications at the same time. It contains functions and resources that can be shared by multiple programs, making it more efficient and easier to maintain.

2. How is Compaq Visual Fortran 6.6 related to DLLs?

Compaq Visual Fortran 6.6 is a software development environment used for creating programs in the Fortran programming language. It allows developers to create DLLs, which can then be used by other programs written in Fortran or other languages.

3. What is the purpose of a Module in Compaq Visual Fortran 6.6?

A Module in Compaq Visual Fortran 6.6 is a separate unit of code that can be shared by different programs. It contains variables, functions, and subroutines that can be accessed by other programs, making it easier to reuse code and improve program efficiency.

4. How do I create a DLL using Compaq Visual Fortran 6.6?

To create a DLL using Compaq Visual Fortran 6.6, you can use the "DLL" project type in the New Project dialog. This will generate a template for a DLL project, which you can then customize and add your own code to create the desired functions and resources.

5. Can DLLs created with Compaq Visual Fortran 6.6 be used with other programming languages?

Yes, DLLs created with Compaq Visual Fortran 6.6 can be used with other programming languages that support DLLs, such as C, C++, and Visual Basic. This allows for cross-language development and integration of different programs.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • New Member Introductions
Replies
1
Views
370
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
Back
Top