Problem linking Fortran to C routine in static library

Problem linking Fortran to C routine in static library

Using vs2010 and IVF2013

Using Fortran I can call a C routine from a C dll to call a C routine from a static library.    

I would like to bypass creating a C dll and call the routine from the static library directly.  When I try I get the following error:

Use_Log.obj : error LNK2019: unresolved external symbol __imp___CusageWebLog referenced in function USE_LOG

The Fortran calling routine is USE_LOG.

This is the interface block written in the same format I would use to call the routine from a C dll.

INTERFACE
  INTEGER FUNCTION CusageWebLog(server, port, script, application, log, message)
    !DEC$ ATTRIBUTES DLLIMPORT :: CUSAGEWEBLOG
    !DEC$ ATTRIBUTES DECORATE, ALIAS:'_CusageWebLog' :: CUSAGEWEBLOG
    CHARACTER(LEN=50)  :: server
    INTEGER(KIND=2)    :: port
    CHARACTER(LEN=50)  :: script
    CHARACTER(LEN=50)  :: application
    CHARACTER(LEN=100) :: log
    CHARACTER(LEN=50)  :: message
    !DEC$ ATTRIBUTES REFERENCE :: server, script, application, log, message
END FUNCTION CUSAGEWEBLOG

Using Dumpbin to view the static library cusage.lib shows the following info for the routine CusageWebLog which I'm trying to use:

Dump of file cusage.lib
File Type: LIBRARY
COFF SYMBOL TABLE
03C 00000000 SECT10 notype ()    External     | _CusageWebLog

Since I'm trying to get the routine from a static library instead of an import library, is the format used for calling it different?

Thanks,
Mike

 

publicaciones de 5 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

I just realized that I do not need the DLLIMPORT in the interface block.  Building now results in the error:

1>Use_Log.obj : error LNK2019: unresolved external symbol __CusageWebLog referenced in function USE_LOG

I do have Cusage.lib listed as a linker:Input:Additional Dependency.

Mike

 

 

(Post the declaration prototype for the C function.  Is the C function expecting string lengths to be passed?  Does it want the strings null terminated?)

You appear to have a stray leading underscore in the fortran alias specification.

Rather than all that !DEC$ nonsense you are better off these days using Fortran 2003's BIND(C) feature.

Correct IanH, I had an underscore leading the routine name.  The linker found the correct routine, but it calls 15 other routines in the same Cusage.lib which I can see using Dumpbin.  The linker now complains about an unresolved external for each.  I had thought it would be able to resolve these calls if I called their calling routine  CusageWebLog.

I guess I'll just go back to calling the original C routine which was calling  CusageWebLog since it works fine that way.

I'm not familiar with the Bind(C) feature - I'll check it out.

Thanks

 

If you are able to link to the C function in the static library, and that C function is calling other C functions in the static library, it should all work fine.  Something else is astray...

Inicie sesión para dejar un comentario.