0

I want to link my Fortran code with this Fortran made DLL.

In simple way...

Fortran program (editable code) --LINK-- Fortran DLL (uneditable) (linking method via Fortran program code??)

I want to make a program where I do not want to show my codes (this part will be in DLL form).

For example:

i have a code for DLL in intel fortran that is

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

now I want to use this DLL in another program . The new program is separate program and I want to use this DLL in the Intel fortran written below.


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

The error is:

Error   1    error LNK2019: unresolved external symbol __imp__TWICE referenced in function _MAIN__  twiceTEST.obj   
Error   2    fatal error LNK1120: 1 unresolved externals    Debug\twiceTEST.exe 
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
rairkz
  • 3
  • 1
  • 7
  • 1
    Please do not ask people to send you anything, that is completely off-topic here. Ask for a solution of your problem. Show us what you do in simple steps and in detail. Show your error messages. Show some simple code. – Vladimir F Героям слава Mar 09 '17 at 13:46
  • Enter more info after clicking at the **edit** below the question http://stackoverflow.com/posts/42696140/edit We will need to see **much more**. Show your **ifort commands** you are executing and the **error messages**. – Vladimir F Героям слава Mar 09 '17 at 15:32
  • And which command are you running when you get that error message? Or what are you clicking at? Or what are you doing when it prints that message? See also http://stackoverflow.com/questions/5159353/how-can-i-get-rid-of-the-imp-prefix-in-the-linker-in-vc – Vladimir F Героям слава Mar 09 '17 at 15:43
  • when I am putting the DLL file in the same project file along with the fortran code that is main program here it is TestToCallDLL. Then I am using build command. Here it is the problem. If I am using both the codes in same sourceCode folder, then its running. But I dont want to use the code instead i want to use DLL file. – rairkz Mar 09 '17 at 15:46
  • How you are putting the DLL there? How are you telling the compiler how to use the DLL? Be specific. – Vladimir F Героям слава Mar 09 '17 at 15:50
  • I am using the code written in second part. I am just putting the DLL file in the project folder. – rairkz Mar 09 '17 at 15:52
  • You should really read Building Executables that Use DLLs https://software.intel.com/en-us/node/535309 You cannot just copy the DLL, you must tell the compiler to use the DLL. – Vladimir F Героям слава Mar 09 '17 at 15:52
  • But first read this **You do not add a .DLL as a linker dependency - you add the .LIB created when the DLL was built.** https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/291176 – Vladimir F Героям слава Mar 09 '17 at 15:55
  • I am sorry ... Here I am not getting the things. If possible please tell me the clicking like Project > Add Existing Item> . The things are a mess. I am not getting them. Please help this. – rairkz Mar 09 '17 at 16:04
  • Find "Additional Dependencies", click on it and add the `.LIB` file there. Note that I am not a Windows programmer, I am just trying to guide you before some Windows Intel Fortran expert tells something more. – Vladimir F Героям слава Mar 09 '17 at 16:08
  • Thanks a lot sir. Now i understand my mistake. I just added the .lib file in my source code folder> then put the .dll file in the project folder > then build and debug run the project successfully. Thanks a ton!!! – rairkz Mar 09 '17 at 16:39

1 Answers1

0

The .LIB file generated by the compiler when creating the .DLL must be used during linking. Add it as a dependency. You can also copy it to the new project directory.

See Calling Fortran DLL from C++ using Visual Studio 2008 in the Intel Fortran for Windows support forum for more.