- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Replace:
with:
You named your source file with a .cpp file type, and that implies C++ name mangling.
Steve
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok. In that case, you want this instead:
!DEC$ ATTRIBUTES ALIAS:'_cblk' :: cblk
!DEC$ ATTRIBUTES ALIAS:'_cblk' :: cblk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page