Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

linking library

jaeger0
Beginner
796 Views
I'm trying to make a Wrapper for a C-build library, however I get the the error message
error LNK2019: unresolved external symbol _asc_initializenetwork@20 referenced in function _MAIN__
What means 20 ?
I have added the library in the Linker->input->Additional Dependencies. So either the name of the function is wrong, or something else. Is there a method to view the declarations of a library subroutine by the dnmnet.lib file. May I have an other problem here ?

INTERFACE
function ASC_initializeNetwork (role,acceptorPort,timeout,network,options)
!DEC$ OBJCOMMENT LIB:'DCMNET.lib'
! Specify C calling and naming conventions
!DEC$ ATTRIBUTES STDCALL :: ASC_initializeNetwork
! input variables
integer role ! T_ASC_NetworkRole
integer acceptorPort
integer timeout
! type(T_ASC_NETWORK)
integer network
integer(4) options
! output variables
integer(2) iErr

END function
end interface
0 Kudos
5 Replies
anthonyrichards
New Contributor III
796 Views
Normally, I would suggest doing a DUMPBIN /symbols DCMNET.LIB on the library to list the symbol names and see what it has for the routine you list. Then it might just require an ALIAS directive added to the Fortran to get the Fortran compiler to generate the correct symbol to match. There may be a problem with the leading underscore, or with the trailing '@20', or the case, or a mixture of all three!

0 Kudos
TimP
Honored Contributor III
796 Views
@20 means you have set stdcall compatible checking of stack space used for argument passing. For the last 8 years or so, cdecl is normally used by Visual Studio, but you must choose the same ABI for your C and Fortran.
0 Kudos
Steven_L_Intel1
Employee
796 Views
Quoting - anthonyrichards
Then it might just require an ALIAS directive added to the Fortran to get the Fortran compiler to generate the correct symbol to match. There may be a problem with the leading underscore, or with the trailing '@20', or the case, or a mixture of all three!


I recommend against using ALIAS unless you absolutely know that the caller is using STDCALL with undecorated names (VB, etc., will do this.) I have seen people get into trouble by using ALIAS to "fix" a calling convention mismatch.
0 Kudos
jaeger0
Beginner
796 Views

I recommend against using ALIAS unless you absolutely know that the caller is using STDCALL with undecorated names (VB, etc., will do this.) I have seen people get into trouble by using ALIAS to "fix" a calling convention mismatch.

Currently I do not have the whole source code for the library. I found out, that the library is using the __cdecl convention. However If I use !DEC attributes c :: ASC_initializeNetwork
I still get the error message unresolved external symbol..
However the function ASC_initializeNetwork is defined in the source code I have.
0 Kudos
Steven_L_Intel1
Employee
796 Views

If you just say "attributes c", then the name is downcased to asc_initializenetwork (with a leading underscore on IA-32). If the name is as it shows there, then remove the ATTRIBUTES C directive and use this line instead:

function ASC_initializeNetwork (role,acceptorPort,timeout,network,options) BIND(C,NAME='ASC_initializeNetwork)

You will also need to add the VALUE attribute to the arguments that are passed by value (I'm sure some of them are).
0 Kudos
Reply