[NEWBIE] Unresolved Links in Fortran-C mixed Languages

[NEWBIE] Unresolved Links in Fortran-C mixed Languages

Hello,
everytime I try to link my program I get many LNK2001 errors due to libc.lib and dformt.lib and unresolved links. I' m trying to to call a C graphic subroutine from a Fortran code.This is the error log:
Linking...
Searching Libraries
Searching E:Program FilesMicrosoft Visual StudioVC98Libkernel32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Liblibc.lib:
Searching e:Program FilesMicrosoft Visual StudioDF98Libdfqwin.lib:
Searching e:Program FilesMicrosoft Visual StudioDF98Libdformt.lib:
dformt.lib(matherr.obj) : error LNK2005: __matherr already defined in libc.lib(matherr.obj)
Searching e:Program FilesMicrosoft Visual StudioDF98Libdfqw_sdi.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libuser32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libgdi32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libcomdlg32.lib:
Searching e:Program FilesMicrosoft Visual StudioDF98Libdfport.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libwinmm.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libopengl32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libglu32.lib:
Searching C:ProgrammiMicrosoft Visual StudioVC98LIBglut32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98LibOLDNAMES.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libuuid.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libkernel32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Liblibc.lib:
Searching e:Program FilesMicrosoft Visual StudioDF98Libdfqwin.lib:
Searching e:Program FilesMicrosoft Visual StudioDF98Libdformt.lib:
Searching e:Program FilesMicrosoft Visual StudioDF98Libdfqw_sdi.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libuser32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libgdi32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libcomdlg32.lib:
Searching e:Program FilesMicrosoft Visual StudioDF98Libdfport.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libwinmm.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libopengl32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libglu32.lib:
Searching C:ProgrammiMicrosoft Visual StudioVC98LIBglut32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98LibOLDNAMES.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libuuid.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Libkernel32.lib:
Searching E:Program FilesMicrosoft Visual StudioVC98Liblibc.lib:
Done Searching Libraries
main.obj : error LNK2001: unresolved external symbol _C_ROUTINE@36
dfqwin.lib(qwkentry.obj) : error LNK2001: unresolved external symbol __beginthreadex
dfqwin.lib(qwgwnd.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/superbike.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

superbike.exe - 5 error(s), 1 warning(s)

I call the C stuff through the line:

CALL c_routine (theta50,Zf0,l23,r4,r1,rt4,rt1,lf,l1)

I've already set an interface to C i
n the Fortrain main code with:

INTERFACE
SUBROUTINE c_routine (theta50,Zf0,l23,r4,r1,rt4,rt1,lf,l1)

DOUBLE PRECISION theta50 [REFERENCE]
DOUBLE PRECISION Zf0 [REFERENCE]
DOUBLE PRECISION l23 [REFERENCE]
DOUBLE PRECISION r4 [REFERENCE]
DOUBLE PRECISION r1 [REFERENCE]
DOUBLE PRECISION rt4 [REFERENCE]
DOUBLE PRECISION rt1 [REFERENCE]
DOUBLE PRECISION lf [REFERENCE]
DOUBLE PRECISION l1 [REFERENCE]

END SUBROUTINE c_routine
END INTERFACE

I eventually renamed the s

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You have two problems. The first is the __matherr duplicate definition. To fix this, go to Project..Settings..Link and, in the field for libraries and object modules, add dformt.lib to the beginning of the list.

The undefined reference is because Visual Fortran and C have different defaults for calling mechanisms. Add:

!DEC$ ATTRIBUTES C :: c_routine

to your INTERFACE block and you should be ok, as long as in the C code it appears as c_routine and not C_ROUTINE.

I strongly advise you to read the chapter on mixed-language programming in the Visual Fortran Programmer's Guide. Note also that [REFERENCE] is an undocumented extension from MS Fortran PowerStation 1, but it is supported. The documented alternative is !DEC$ ATTRIBUTES REFERENCE. Again, see the Programer's Guide, plus the chapter on directives in the Language Reference Manual, for details.

Steve

Steve

Login to leave a comment.