Software Archive
Read-only legacy content
17061 Discussions

Linking to C DLL

Deleted_U_Intel
Employee
331 Views
I am trying to understand how to link a DLL, created in C, into a fortran executable. To this end I have made very simple source code given below.

// AddIt.cpp // 
 
#include "Addit.h"" 
 
extern "C" 
_declspec(dllexport) 
void _cdecl AddIt(float A, float B, float &C) 
{ 
  C = A + B; 
} 
 
// Fortran Code // 
 
	PROGRAM MAIN 
 
	IMPLICIT NONE 
		 
      INTERFACE 
 
      SUBROUTINE ADD(A,B,C) 
!DEC$ ATTRIBUTES stdcall, DLLIMPORT, ALIAS:'_AddIt'::ADD 
      REAL*4 A,B,C      
	end subroutine ADD 
	END INTERFACE 
 
	real*4 x,y,z 
	x=2.0  
	y=3.0  
	z=0.0  
	 
      CALL ADD(x,y,z) 
 
END PROGRAM MAIN 


The Addit library is included in the compliation of the Fortran code. When I compile and link the Fortran routine I get a linker error as follows:

Searching Libraries
Searching c:CodeTestAddItAddItDLL.lib:
Found _AddIt
Referenced in FORADD.obj
Loaded AddItDLL.lib(AddIt.dll)
c:CodeTestAddItAddItDLL.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3b611128
Error executing link.exe.

It appears that the procedure contained in the DLL is being found, but the linker does not like it. I have plenty of space on the disk (>20 GB). The C DLL was created using Microsoft Visual C++ 6.0.

Any thoughts?
0 Kudos
1 Reply
Steven_L_Intel1
Employee
331 Views
Yep - you're using a MSVC 6-created import library with a version 5 linker. MS changed the library format in an incompatible fashion. Solutions: 1) Upgrade to CVF 6.5, 2) Use the MSVC 6 linker to link, 3) Install VS97 SP3 (see the CVF FAQ for details.)

Steve
0 Kudos
Reply