Software Archive
Read-only legacy content
17060 Discussions

Exchanging data between common block and C struct

jcbreeding
Beginner
1,338 Views
I am porting legacy code from a Sun with mixed Fortran and C. I am trying
to exchange data between a Fortran common block and a C struct( VC++ 6.0). I keep
getting linker error mesages like:

error LNK2001: unresolved external symbol _COM1

I have read the help files and set up a test case that follows their guidelines.
(See below). This test case works. I am sure I have set up the common blocks and structs exactly
like this example but I keep getting the error messages when I try to link
my code which . Any suggestions as to why my code won't link even though it is structured
like the following example?

The C modules are C, not C++. The Fortran is a quickwin project.

Jim Breeding

In Fortran source (tstcom.h):

                PROGRAM TSTCOM 
	IMPLICIT NONE 
 
	INTERFACE 
	  SUBROUTINE c_module 
                    !DEC$ ATTRIBUTES C :: c_module 
	  END SUBROUTINE c_module 
	END INTERFACE 
 
	REAL A,B 
	INTEGER N1,N2,I 
	CHARACTER CARRAY*8,SETCOM(0:7) 
 
	COMMON /COM1/A,B,N1,N2,SETCOM 
               call c_module 
          END 

In C Header (tstcom.h) 
#pragma pack(2) 
extern struct dum { 
	float a; 
	float b; 
	int n1; 
	int n2; 
	char setcom[8]; 
}; 
#pragma pack() 

In C source (c_module.c) 
#include  
#include "tstcom.h" 
 
void c_module() 
{ float aa,bb; 
  int nn1,nn2; 
  char setcom2[8]; 
  extern struct dum COM1; 
 
  aa = COM1.a; 
  bb = COM1.b; 
  nn1 = COM1.n1; 
  nn2 = COM1.n2; 
  strcpy(COM1.setcom,"ijklmnop"); 
} 
0 Kudos
1 Reply
Steven_L_Intel1
Employee
1,338 Views
It would be helpful to see a test case that doesn't work...

Steve
0 Kudos
Reply