- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page