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

LNK error when calling a C routine from a FORTRAN program

camille_dannunzio
522 Views
I am using Compaq visual Fortran 6.6a & Visual C++ 6.0. I have a subroutine display.f that calls a subroutine WRITETIFF.C I have include WRITETIFF.C in my project and it compiles seemlessly however when I link them I get the following LNK error (note the WRITETIFF.OBJ file shows up in the correct directory
Done Searching Libraries
End Pass1
DISPLAY.obj : error LNK2001: unresolved external symbol _WRITETIFF@32
Debug/adved_ns_slice.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe
Do I need to do something special to get display to recognize WRITETIFF.C. I did a /verbose and it is finding all the correct libraries and everything else that it needs. Listedin attachmentis the begining of display.f and the call to WRITETIFF.C and then WRITETIFF.C
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
522 Views
subroutine display
use opengl_gl
use opengl_glut
interface
   integer function WriteTiff(filename, description, &
           xx, yy, wwidth, hheight)
   !DEC$ATTRIBUTES STDCALL, DECORATE, ALIAS: "WriteTiff":: WriteTiff
   !DEC$ATTRIBUTES REFERENCE: WriteTiff
   !DEC$ATTRIBUTES REFERENCE: filename
   !DEC$ATTRIBUTES REFERENCE: description
   character(*):: filename, description
   integer:: xx, yy, wwidth, hheight
   end function 
end interface
On C side:
int __stdcall WriteTiff(char* filename etc.

ALIAS name in Fortran must match the case of C name. REFERENCE attributes for filename and description say that string length should not be passed. REFERENCE attribute for WriteTiff says that all arguments are by reference. __stdcall is not mandatory, but if you omit it in C, you should spell "C" instead of "STDCALL" in Fortran.

Jugoslav

0 Kudos
camille_dannunzio
522 Views
Thank you. I made the changes you suggested and it links without errors but in the compile it gives the following syntex errors (in fact when I inserted your piece of code the !DEC lines are in green indicating that they are comment lines. Is this supposed to be?
Camille
C:Exchangeadveds4_15_04graphicsFortranadved_ns-sliceDISPLAY.f
C:Exchangeadveds4_15_04graphicsFortranadved_ns-sliceDISPLAY.f(9) : Info: Syntax error, found IDENTIFIER 'WRITETIFF' when expecting one of:
!DEC$ATTRIBUTES REFERENCE: WriteTiff
--------------------------------------^
C:Exchangeadveds4_15_04graphicsFortranadved_ns-sliceDISPLAY.f(10) : Info: Syntax error, found IDENTIFIER 'FILENAME' when expecting one of:
!DEC$ATTRIBUTES REFERENCE: filename
--------------------------------------^
C:Exchangeadveds4_15_04graphicsFortranadved_ns-sliceDISPLAY.f(11) : Info: Syntax error, found IDENTIFIER 'DESCRIPTION' when expecting one of:
!DEC$ATTRIBUTES REFERENCE: description
0 Kudos
Jugoslav_Dujic
Valued Contributor II
522 Views
I mistyped -- should be double-colon (::) instead of single.
0 Kudos
Reply