Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29390 Discussions

help converting from WATCOM to Compaq

hepnerta
Beginner
862 Views
Hi,

I am trying to convert some programs from WATCOM FORTRAN/C into the Compaq/MS arena. Things seem pretty straight forward, but I'm having a problem converting routines that try to share common blocks. I thought I had followed the example given, but when I build the program, the common block is listed as an unresolved external symbol at link time. The following illustrates a very simple problem as an example:

***
C CODE

// This code shows how to access a FORTRAN common block from C using
// Compaq/MS

#include

//#pragma aux put "^"
//#pragma aux cblk "^"

#pragma pack (2)
extern struct cb{
long int i, j;
} cblk;
#pragma pack()

void put (void)
{
printf("i = %ld ", cblk.i);
printf("j = %ld ", cblk.j);
cblk.i++;
cblk.j++;

}

***
FORTRAN CODE
***

c This program shows how to access a FORTRAN common block
c from C using Compaq/MS

program MIX5F

INTERFACE TO SUBROUTINE PUT [C, ALIAS:'_put']
END
!DEC$ ATTRIBUTES ALIAS:'cblk' :: cblk

common /cblk/i,j


i =12
j = 10

call put
print *,'i= ', i
print *,'j= ', j
end

The code is compiled with:
cl /c mix5c.c
f90 mix5f.for mix5c.obj

Then, during the link the following error occurs:

mix5c.obj : error LNK2001: unresolved external symbol _cblk
mix5f.exe : fatal error LNK1120: 1 unresolved externals

Any help would be very much appreciated.

Tom Hepner
hepner@spawar.navy.mil
0 Kudos
4 Replies
Steven_L_Intel1
Employee
862 Views
Replace:

extern struct cb{


with:

extern "C" struct cb{


You named your source file with a .cpp file type, and that implies C++ name mangling.

Steve
0 Kudos
hepnerta
Beginner
862 Views
Thanks, but the file is named mix5c.c, not mix5c.cpp, and is just a regular c type file. I did try and put in the

extern "C" struct xb{

and the copiler really seems to not link that - as it complains about error C2059, syntax error : 'string'

But thanks for trying!

Tom
0 Kudos
Steven_L_Intel1
Employee
862 Views
Ok. In that case, you want this instead:

!DEC$ ATTRIBUTES ALIAS:'_cblk' :: cblk
0 Kudos
hepnerta
Beginner
862 Views
Steve,

Many thanks for your help - that is just what I needed to do (and I'll save the C++ info for the conversion of those routines that use c++).

Again, thanks!

Tom
0 Kudos
Reply