×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Calling Fortran DLL inside Fortran Exe

Calling Fortran DLL inside Fortran Exe

Calling Fortran DLL inside Fortran Exe

(OP)
Hi,

here is my exe :

program FortranTestExe
  implicit none
  call FortranTestDLLSub
end program FortranTestExe

And here is my DLL:

subroutine FortranTestDLLSub
   !DEC$ ATTRIBUTES DLLEXPORT::FortranTestDLLSub
    print *,'Hellow World'
end subroutine FortranTestDLLSub

DLL compiliation is fine, but Exe does not link .
I imported in the exe workspace the linked DLL file, with a simpl " add files on project" (I don't know if I should do this..)

Here is the message :

ompiling Fortran...
D:\Win32\DLL\FortranTestExe\FortranTestExe.f90
Linking...
FortranTestExe.obj : error LNK2001: unresolved external symbol _FORTRANTESTDLLSUB@0
dfordll.lib(DFORMAIN.OBJ) : error LNK2001: unresolved external symbol __imp___fpieee_flt
Debug/FortranTestExe.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

FortranTestExe.exe - 3 error(s), 0 warning(s)



I really don't understand how to do to so that the "Exe" knows  the "DLL" ..
Could someone help me ?
 thanks



 

RE: Calling Fortran DLL inside Fortran Exe

You need to export from the DLL and import from the main.  The code for the main will look something like

CODE

program FortranTestExe
  implicit none
   !DEC$ ATTRIBUTES DLLIMPORT::FortranTestDLLSub
  call FortranTestDLLSub
end program
Note that if you are using common blocks, they have to be enclosed between two /

RE: Calling Fortran DLL inside Fortran Exe

(OP)
Thanks !

It didn't work at first, but it was necessary to do this indeed.

I also had to add "FortranTesyDLLSub.lib" file into my "exe" project, and then it worked.
 

RE: Calling Fortran DLL inside Fortran Exe

Hi,

I didn't expect susch a quick answer, I understand from your answer that it's a workspace option at start up.

I tried in Microsoft Developer Studio from 1994-1995 for the moment, I don't have CVF available here today (It's also called Fortran power station 4.0)

My main is:

CODE

PROGRAM TestToCallDLL
IMPLICIT NONE
!DEC$ ATTRIBUTES DLLIMPORT::TWICE
REAL :: x,y

WRITE(*,*)'x?'
READ(*,*)x
CALL Twice(x,y)
WRITE(*,*)'x twice = ',y

END PROGRAM TestToCallDLL

and my subroutine is:

CODE

SUBROUTINE TWICE(x,y)
IMPLICIT NONE
!DEC$ ATTRIBUTES DLLEXPORT::TWICE
REAL, INTENT(IN) :: x
REAL, INTENT(OUT) :: y
y=2*x
END SUBROUTINE TWICE

I don't really understand the !DEC$ option, everything that starts with a ! is supposed to be just a comment, isn't it?

Besides I get exactly the same link error as the post to which you refer. My DLL compiles, next I place the DLL in my exe workspace and try to compile the exe but get a link error (no libs files are found in the DLL workspace with respect to the other post).

Why does it not link, and can I pass arrays the same way?

Thanks!!

RE: Calling Fortran DLL inside Fortran Exe

(OP)
Hi, I am not sur I understand you well.

I added ( " Add File to project " ) the .lib files , and it was enough to remove the first Link Error:

FortranTestExe.obj : error LNK2001: unresolved external symbol _FORTRANTESTDLLSUB@0


For the second one :
dfordll.lib(DFORMAIN.OBJ) : error LNK2001: unresolved external symbol __imp___fpieee_flt

I still don't know what I miss,but it must be something similar.


Things with "!" are special  instructions for the compiler

RE: Calling Fortran DLL inside Fortran Exe

It depends on which version of CVF you are using.  On V10 and V11, you shouldn't be getting this error.  On V7, you need to add one of the libm libraries, depending on your compilation model.  Have a look at \Program Files\Intel\Compiler70\IA32\Lib.  You will see libm.lib, libmmd.lib, libmmt.lib.  In the project properties, have a look at Fortran/library.  If it is single threaded, use libm.lib, multithreaded use libmmt.lib, multithreaded dll use libmmd.lib.

Gerry - I'll dig out my Powerstation compiler and let you know tonight.  If I remember correctly, the API is similar to but not quite like VS6.

RE: Calling Fortran DLL inside Fortran Exe

Thanks a lot!!!

I've been send on a trip, but wil let you know whether it works with the other compiler as soon as I can.

This compiler dependency was one of the reasons that I'm interested in doing the trick with gfortran.

Once controlling the making of DLL's (sounds like the making of a movie..), I want to make DLL's to be coupled with commercial codes.

Gerrit

P.S. I like the old powerstation 1994-1995 compiler because it warns you for unused variables (not being a professional programmer, I didn't manage to turn that on in our CVF compiler). So I write most of my codes on the old powerstation and when they're clean I compile them on CVF or gfortran.

RE: Calling Fortran DLL inside Fortran Exe

I see that in the hurry I made a mistake in answering to the right post, I gave my answer meant for "How to make DLL's in fortran" to "Calling Fortran DLL inside Fortran Exe" in stead.

It doesn't matter that much I think, both posts are on the same subject...  ...apologies anyway

RE: Calling Fortran DLL inside Fortran Exe

(OP)
After HOURS of reserach , I managed to get rid of the second compilation error:
dfordll.lib(DFORMAIN.OBJ) : error LNK2001: unresolved external symbol __imp___fpieee_flt

I made a Copy/paste of the solution it, because there's no link on it. I found it inside a archive Zip file on HP website...
I attached also a zip file containig the fixes mentioned in the text below.



Q1036 - Unresolved symbol __imp___fpieee_flt when linking after installing VS6 (VS98) SP4 or later
 

Platforms: X86
Versions: 6.x
Fixed in version: 6.5A
Article created: 12 July 2000
Article revised: 29 May 2001

Description: After installation of Microsoft Visual Studio 6.0 (also called Visual Studio 98) Service Pack 4 or later (VS98 SP4, SP5, etc.), attempts to link Visual Fortran applications which link against the DLL form of the run-time libraries get a link error similar to the following:

dformd.lib(DFORMAIN.OBJ) : error LNK2001: unresolved external symbol __imp___fpieee_flt

The library name may also be dforrt.lib.

Explanation: Visual Fortran uses a routine from the Microsoft Visual C run-time library for handling floating point exception fixups. In VS98 SP4, Microsoft made an incompatible change in the structure of the Visual C DLLs so that import libraries for other DLLs which referenced this entry point in the MS DLLs would no longer be able to find it. VS98 SP5 includes the same change.

Solution: We have developed an update for Visual Fortran 6.1A and 6.5 which works around the incompatibility by modifying the Visual Fortran DLL import libraries. DO NOT INSTALL THIS UPDATE UNLESS YOU HAVE VISUAL FORTRAN 6.1A OR 6.5 AND VS98 SP4 or later INSTALLED! Visual Fortran 6.1 and 6.5 includes VS98 SP3 components -the only way to get VS98 SP4 is if you have Microsoft Visual Studio products (eg. Visual C/C++) and obtain SP4 separately from Microsoft. It is not possible to install VS98 Service Packs if you have Visual Fortran only and no Microsoft Visual Studio products. If you install this update and do not have VS98 SP4 or later installed, programs may fail to link or run.

If you do not yet have Visual Fortran 6.1A or 6.5, you must upgrade to one of these before installing this update. For information on upgrading to 6.5, the current version, see the 6.5 page. Note that the 6.x-6.5 upgrade includes this fix. If you have 6.0 or 6.1 and want to upgrade to 6.1A only, see the 6.1A page.

To install the VS98 SP4 fix for X86 systems running Visual Fortran 6.5 AND Microsoft Visual Studio 98 SP4, download and run SP4FIX65I.exe - 147 KB (151,040 bytes), last updated September 20, 2000.

If you have version 6.5A, this fix is automatically applied if Visual Studio 98 SP4 or later is detected on your system. However, some users who have installed MS Visual Basic and not Visual C/C++ report that they need this fix applied separately. For 6.5A systems, if the 6.5A update did not announce that it was installing the fix, download and run SP4FIX65AI.exe - 147 KB (150,528 bytes), last updated April 19, 2001.

To install the VS98 SP4 fix for X86 systems running Visual Fortran 6.1A AND Microsoft Visual Studio 98 SP4, download and run SP4FIX61I.exe - 147 KB (151,040 bytes), last updated July 12, 2000.

VS98 SP4 is not available for Alpha systems, so no update is needed for Alpha.

The update modifies DFORRT.LIB and DFORMD.LIB in the ..\DF98\LIB folder. Backup copies of the updated libraries are placed in ..\DF98\Backup after the update completes.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close