calling a c function from fortran

calling a c function from fortran

I have been attempting to access a c function that is located in a .dll file. The function is called PSLM_GetKey, and it returns an integer type. My interface for the c function is below:

INTERFACE
FUNCTION PSLM_GetKey
!DEC$ ATTRIBUTES C :: PSLM_GetKey
!DEC$ ATTRIBUTES DLLImport :: PSLM_GetKey
END FUNCTION PSLM_GetKey
END INTERFACE

Within my fortran code, I attempt to call the fuction using:
ikey = PSLM_GetKey()

When compiling, I receive the following error:
unresolved external symbol _pslm_getkey

Is there anything obvious that I am doing incorrectly? Is it necessary to have the dll's .lib file added to my project? What if I only have access to the .dll file itself?

Thanks, Barry

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Yes, it is necessary to have dll's .lib file inserted to your project. Moreover, you should take care of name mangling, which is different in CVF, C and C++. If adding .lib to your project still doesn't work (linker error), you should examine real mangled name of C function using:

dumpbin /exports xxx.dll

and add an ALIAS directive to INTERFACE block (such as !DEC$ATTRIBUTES ALIAS: '_PSLM_GetKey':: PSLM_GetKey -- case is important). Note that if the C dll was compiled with VC++ and extern "C" directive was ommited from .cpp file, you could get as ugly a mangled name as ?_PSLM_GetKey@YAXXHUZ.

Jugoslav

Jugoslav www.xeffort.com

Login to leave a comment.