- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am calling a C function defined in a static library as:
extern "C" long getnumparams(long* modHandle);
Dumpbin shows the object name as:
_getnumparams
which is what I would expect.
My Fortran codedefinesthis interface:
interface
integer function getnumparams(id)
!dec$attributes c, alias : '_getnumparams' :: getnumparams
integer function getnumparams(id)
!dec$attributes c, alias : '_getnumparams' :: getnumparams
integerid
end function getnumparams
end interface
end function getnumparams
end interface
and calls the routine thus:
numparams = getnumparams(myId)
The linker complains that it can't find
Linking...
Creating library Debug/myLib.lib and object Debug/myLib.exp
myRoutine.obj : error LNK2001: unresolved external symbol _GETNUMPARAMS@4
Creating library Debug/myLib.lib and object Debug/myLib.exp
myRoutine.obj : error LNK2001: unresolved external symbol _GETNUMPARAMS@4
In other words, for an interface declaring a C function, it seems that the compiler is not applying the C attribute, i.e. not removing the @argument size name decoration. Can anyone see what I'm doing wrong, or is this a compiler bug?
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
btw, I am using CVF 6.6b.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would say that the interface isn't visible where you're doing the call.Note that the lowercase alias isn't used either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the quick reply Steve. I did manage to fix it almost as soon as I posted the second message! I put the interface into a module and it linked nicely.
However, I am still a bit confused. You say the interface isn't visible when the call is made. The interface was declared with the variable declarations in the subroutine that the C function was called from. The subroutine is in a fixed format file (.for). Thenew module is contained in a free format file.
What part of this is the magic incantation that makes it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would have to see the actual source in order to comment intelligently.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is an approximation of the 'before' code :
Code:
subroutine someroutine() implicit none interface integer function getnumparams(id) !dec$attributes C, alias : '_getnumparams' :: getnumparams integer id end function getnumparams end interface integer nparms integer myid ! myid = 12 nparms = getnumparms(myid) end
Moving the interface from this method to a new module fixes the link errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Got it. You went past column 72 in the directive, since you're using fixed source form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
D'oh! Is my face red! Thanks for your help Steve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Happens all the time... Things such as this are why I always use free-form in my own coding.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page