Hello,
I am having problems importing a DLL into my current Fortran project. The DLL file I am trying to import, fdlltest.dll, has the following functions defined when I do dumpbin /exports:
C:\temp>dumpbin /exports fdlltest.dll Microsoft (R) COFF/PE Dumper Version 12.00.40629.0 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file fdlltest.dll File Type: DLL Section contains the following exports for fdlltest.dll 00000000 characteristics 560ED478 time date stamp Fri Oct 02 14:01:12 2015 0.00 version 1 ordinal base 3 number of functions 3 number of names ordinal hint RVA name 1 0 00001000 add2i 2 1 00001010 add2r 3 2 00001040 simpson Summary 1000 .data 1000 .rdata 1000 .reloc 1000 .rsrc 1000 .text
Next, I need to know step-by-step how to import the add2i, add2r, and simpson functions from this DLL located in C:\temp into my current Fortran project. I do not want examples with *.lib, since the actual DLL I want to use once I get past this example does not have a companion *.lib. This is my Fortran code which is supposed to generate an EXE that is linked to the DLL file:
program fdllrun implicit none INTERFACE INTEGER FUNCTION add2i(a,b) !DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"add2i" :: add2i !DEC$ ATTRIBUTES REFERENCE::a, b INTEGER, intent(in), value:: a, b END FUNCTION add2i REAL FUNCTION add2r(a,b) !DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"add2r" :: add2r !DEC$ ATTRIBUTES REFERENCE::a, b REAL, intent(in), value:: a, b END FUNCTION add2r REAL FUNCTION simpson(f, a, b, n) !DEC$ ATTRIBUTES DLLIMPORT, ALIAS:"simpson" :: simpson !DEC$ ATTRIBUTES REFERENCE::f, a, b, n EXTERNAL f real, intent(in), value :: a, b integer, intent(in), value :: n END FUNCTION simpson END INTERFACE ! Variables INTEGER :: i1, i2, ians i1=1 i2=2 ! Body of fdllrun ians = add2i(i1, i2) print '(I3)', ians end program fdllrun
I tried to right click on my project and do Add -> Existing Item, then browse to the DLL file located in C:\temp, then Build All. It does not work. The errors I get when I try to compile are:
Error 1 error LNK2019: unresolved external symbol __imp_add2i referenced in function _MAIN__ fdllrun.obj
Error 2 fatal error LNK1120: 1 unresolved externals Release\fdllrun.exe