Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Fortran DLL inside Fortran Exe

Status
Not open for further replies.

flamandier

Programmer
Sep 25, 2009
7
FR
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



 
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 /
 
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.
 
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!!
 
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
 
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.
 
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.
 
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
 
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.
 
 http://theslysite.free.fr/upload/Download/CVF66C3.zip
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top