- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I recently 'inherited' some FORTRAN code that makes use of C functions using the 'INTERFACE' statement and am in the process of rebuilding the FORTRAN code as an 'x64' application, which means that I have to rebuild the C libraries as well. I can (successfully) build these as either (Configuration Type) a Dynamic Library (.dll) (this produces .dll and .lib files; I can then copy the .dll file to the location of the .exe file for the FORTRAN code and then list the .lib file in the Linker 'Additional Dependencies' for the FORTRAN build) or (alternatively) build a Static Library (.lib) (this produces a .lib file that is listed in 'Additional Dependencies').
Unfortunately ...
- I cannot post any of this code (sorry!)
- the result from using either option (above) is the same: I get 'unresolved externals' error for each function call (LNK2019 in the Linker) and then the compiler lists the associated .lib file as being 'unused'
I have very little experience with FORTRAN code that calls C functions and would appreciate any assistance--thanks ...
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Change the line to:
!DEC$ ATTRIBUTES C, DECORATE, ALIAS:"CreateUniform" :: CreateUniform
and make similar changes elsewhere. You could also do away with the ATTRIBUTES line by using an INTERFACE block that defines the routine with BIND(C,"CreateUniform"), but that may require further changes such as adding VALUE to pass-by-value dummy arguments.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The steps you say you took look fine. Can you give an example of one of the LNK2019 errors and show the declaration of that routine in the C code? (Just the function itself, no actual code.) If you want to anonymize the name, OK, but do not change case or any prefix or suffix characters.
My guess is that you have a mismatch in expectations for external name decoration. In particular, if your Fortran code explicitly has an alias of the form "_funcname", with the leading underscore, that won't be correct for x64.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I believe that you are completely correct ... all of the errors seem to be of the form:
INSENS.obj: error LNK2019: unresolved external symbol _CreateUniform referenced in function INSENS
for this same function, the C code (library) has the declaration:
void DllExport MYCALLBACK CreateUniform(<arglist> ...)
and, for this same function, the file INSENS.FOR contains the line:
!DEC$ ATTRIBUTES C, ALIAS:"_CreateUniform :: CreateUniform
so, I'm not sure what I need to do--should I just delete this 'alias' line for all of these functions, as they won't be needed for building the 64 bit application? thanks ..
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
well, I just deleted all of the 'ALIAS' lines, and I'm still seeing 'unresolved external' errors ... in my example above, it would be (w/o the '_'):
INSENS.obj: error LNK2019: unresolved external symbol CreateUniform referenced in function INSENS
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Change the line to:
!DEC$ ATTRIBUTES C, DECORATE, ALIAS:"CreateUniform" :: CreateUniform
and make similar changes elsewhere. You could also do away with the ATTRIBUTES line by using an INTERFACE block that defines the routine with BIND(C,"CreateUniform"), but that may require further changes such as adding VALUE to pass-by-value dummy arguments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hmmm ... now I'm getting:
error #7794: Only a function or subroutine subprogram may have the DEC$ ATTRIBUTES directive DECORATE specifier. [CREATEUNIFORM]
this makes no sense because 'CreateUniform' (et al) IS a subroutine ... I'll look up this error ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
well, it turned out that the actual name of the subroutine was extending past 132 columns ... so I moved the 'DECORATE' line a few columns to the left, and now everything seems to build ... thanks so much for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Glad to hear it. Fixed-form source, eh? You can also add a second !DEC$ ATTRIBUTES line to specify additional attributes.
Please mark my reply above as the answer to your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm so sorry--I think that I mistakenly marked my reply as the solution rather than yours ... is there a way to 'undo' this?
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks as if a moderator fixed it. Thanks.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page