Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

Calling C from Fortran

hector_t
Beginner
695 Views
I have a solution similar to the sample Fortran_Calls_C.

My c lib compiles ok, but when i try to bulid the fortran program i get a Link error:

1 error LNK2019: unresolved external symbol _get_tflag referenced in _GET...

this is my c function
extern "C" int GET_TFLAG (int TIME_ARRAY[])
{
struct tm tm0;

tm0.tm_sec = TIME_ARRAY[0];
tm0.tm_min = TIME_ARRAY[1];
tm0.tm_hour = TIME_ARRAY[2];
tm0.tm_mday = TIME_ARRAY[3];
tm0.tm_mon = TIME_ARRAY[4];
tm0.tm_year = TIME_ARRAY[5];
tm0.tm_wday = TIME_ARRAY[6];
tm0.tm_yday = TIME_ARRAY[7];
tm0.tm_isdst = -1; //de esta manera fuerzo a que mktime calcule el flag horario

mktime(&tm0);

return tm0.tm_isdst;
}

and this is my interface (inside a fortran subroutine)
INTERFACE
INTEGER FUNCTION GET_TFLAG(TIME_ARRAY)
!DEC$ ATTRIBUTES C :: GET_TFLAG
INTEGER*4 TIME_ARRAY(9)
!DEC$ ATTRIBUTES REFERENCE :: TIME_ARRAY
END FUNCTION GET_TFLAG


Thank you very much


0 Kudos
2 Replies
Steven_L_Intel1
Employee
695 Views
When you say ATTRIBUTES C in Fortran, the name is converted to lowercase by default. Your actual C routine is uppercase.

My advice in this case, assuming you are using Intel Visual Fortran, is to remove the ATTRIBUTES lines, both of them. You don't need them. I also note that you declare the array to be 9 elements in the Fortran code but the C code uses only 8.
0 Kudos
anthonyrichards
New Contributor III
695 Views

Do a

DUMPBIN /EXPORTS YOURCLIBRARY.LIB

to get the table of exported symbols, then look for the symbol stored for your 'C' Get_Flag routine, then add an ALIAS attribute for the exact symbol name (observing the case-sensitivity of C...) to your Fortran Interface.

0 Kudos
Reply