I have written some wrapper functions in c++ for some old Fortran (g77, I think) code. I created the .dll and .lib using an old Visual Fortran compiler, and have everything linked up and working in visual studio.
The problem I have now is creating an equivalent 64 bit version. I have installed gfortran and created a 64 bit .dll but no .lib was generated along with it, and I can't seem to link to the DLL or call any of the fortran functions without it.
I created my 64 bit .dll with the commands...
$ gfortran -c {filenames.for}
$ gfortran -m64 -shared -mrtd -o dll_foo.dll {filenames.o}
And here is a sample subroutine from the fortran...
SUBROUTINE KFACT(TR, RHOL, RHOV, FLIQ, FVAP, XK, IWANT, PROPR)
!DEC$ ATTRIBUTES DLLEXPORT :: KFACT
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
INCLUDE 'nprop.cmn'
DIMENSION PROPR(NPROP)
DIMENSION IWANT(NPROP)
C
C SET IWANT VECTOR TO RETURN FUGACITY COEFFICIENT
C
CALL IVZERO(IWANT, NPROP)
IWANT(13) = 1
C
C CALL PROP2 TO RETURN VAP AND LIQ FUGACITY COEFFICIENTS
C
CALL PROPS2(IWANT, 0, TR, RHOL, PROPR)
FLIQ = PROPR(13)
CALL PROPS2(IWANT, 0, TR, RHOV, PROPR)
FVAP = PROPR(13)
C
XK = FLIQ / FVAP
C
RETURN
END
C
SUBROUTINE PDP(DEL, TR, PR, DPRDD, IWANT, PROPR)
How can I create a .dll and .lib file to be linked to, from my Visual Studio (2005) c++ project?
/////////////////////////////UPDATE/////////////////////////////
I have been able to create a .lib file by using the following commands...
ar -cru libName.lib {filenames.o}
ranlib libName.lib
After adding this lib to my Additional Dependencies in VS, I get LNK errors for all of the fortran functions when they are called. The fortran declarations in the c++ look like...
extern "C" void PSAT(double& TK, double& PMPA, double& RHOL, double& RHOV, int IWORK[], double PROPR[], int& IERR);
and the LNK errors for this function...
error LNK2028: unresolved token (0A00004A) "extern "C" void __cdecl PSAT(double &,double &,double &,double &,int * const,double * const,int &)" (?PSAT@@$$J0YAXAEAN000QEAHQEANAEAH@Z) referenced in function "double __cdecl PFTH(double,double,int)" (?PFTH@@$$FYANNNH@Z)
error LNK2019: unresolved external symbol "extern "C" void __cdecl PSAT(double &,double &,double &,double &,int * const,double * const,int &)" (?PSAT@@$$J0YAXAEAN000QEAHQEANAEAH@Z) referenced in function "double __cdecl PFTH(double,double,int)" (?PFTH@@$$FYANNNH@Z)
I have tried adding different directives in the fortran code to resolve the names like but I have been unsuccessful.
I don't know if the problem lies in the c code, the fortran code, or the creation of the .lib file.
Any help would be greatly appreciated!