Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

calling a c function from fortran

Intel_C_Intel
Employee
350 Views
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
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
350 Views
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
0 Kudos
Reply