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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import dll in a fortran program

Status
Not open for further replies.

use4fortran

Technical User
Nov 2, 2011
2
US
Hello !!

I have created a fortran dll. The dll compiled successfully and gave me the ".lib" and ".dll" files. I tried to call this dll in another program and it gives me the follwing errors:

Error 1 error LNK2019: unresolved external symbol __imp__CREATEDLL referenced in function _MAIN__ testdll.obj
Error 2 fatal error LNK1120: 1 unresolved externals Debug\testdll.exe

I figured that the second error is a result of the first. But how do I get rid of the first error? Can somebody please HELP !!!

*************************************************************
!Code for dll:
subroutine createdll(message)
!dec$ attributes dllexport :: createdll

implicit real*8(a-h,o-z)
character*200 message

write(*,10) message
10 format(a100)

end subroutine
*************************************************************
! Code to use the dll
program test_dll
!dec$ attributes dllimport :: createdll

implicit real*8(a-h,o-z)
character*200 test_message

test_message = 'This is a test for creating fortran dll'
call createdll(test_message)

stop
end program
 
1) Are you using Visual Studio or running this from the command line?

2a Visual Sudio) If you are using visual studio, are both projects in the same solution or are they in different solutions?

3a VS Same) Set the DLL as a dependency of the test program

3b VS different) Add the lib file in the linker input

2b Command Line) You need to add the lib file to the link line.

Once you have linked it, you will need to put the DLL either on the path or in the same directory as the exe
 
Hi xwb: Thanks for your reply. I am a fairly new user of MS Visual studio. I was using Compaq VF until now. As for your questions:

1) I am now using IVF in the MS VS environment.
2) Both projects are different solutions.
3) I added the lib file in the linker inout under additional dependencies.

How do I put the dll on the path?

Thanks in advance.
 
Putting the DLL on the path. Lots of ways

1) Copy the dll to the same directory as the executable

2) Have a look at your path variable, copy the dll into one of the directories listed in the path

3) Change your path to

PATH <directory containing the DLL>;%path%

4) Say your directory structure is like this

+--Project
+--Test Program
+--Debug -- your obj, exe are here
+--DLL
+--Debug -- your obj, lib and dll are here

Under Project Properties/General, set the Output Directory to ..\$(ConfigurationName). You will get something like

+--Project
+--Debug -- your exe, lib and dll will be here
+--Test Program
+--Debug -- your obj is here
+--DLL
+--Debug -- your obj is here

That way, whenever you run the program, the DLL will always be in the same directory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top