mixed C/Fortran linking problems with ifc 7.1

mixed C/Fortran linking problems with ifc 7.1

Hello,

I am able to build my application, which is a mixed C/Fortran application, on windows without problems using icl and ifl (7.1)

However, when I port the source code to Linux, I cannot have my C functions linked to the Fortran objects. Below is small mixed C/F9x application that illustrates what I experience in my original application.

There is a "main.for" which calls a C function (fact.c) to compute the factorial of an integer.

When linking the objects with ifc 7.1, I get the following error.

$> ifc src/main.o src/fact.o -o src/fact -lcxa -C90

src/main.o(.text+0x20): In function `main':

: undefined reference to `FACT2'

Here are the files. My linux box is RH 8.0. Any help would be truly appreciated. Note, the function name in fact.c is (deliberately) aliased and made uppercase.

C-- file 1: main.for --

CCCCCCCCCCCCCCCCCCCCC

MODULE CFACT

INTERFACE

INTEGER FUNCTION FACT( N)

!MS$ ATTRIBUTES C,ALIAS:'FACT2'::FACT

INTEGER N [REFERENCE]

END FUNCTION FACT

END INTERFACE

END MODULE

CCCCCCCCCCCCCCCCCCCCCC

program main

use CFACT

implicit none

integer f1,f2,f3

f1 = FACT(10)

write (*,*) 'fact = ', f1

stop

end

/**** file 2: fact.c *****/

int FACT2( int *n)
{
int i, f = 1;

for (i=1;i<=*n;i++) f = f * i;

return f;
}

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

It looks like you are running into the difference between the usual Windows and linux Fortran link symbol mangling. ifc uses lower case symbols with appended underscore.
For example, you might build your C file like:
icc -DFACT2=fact2_ -c src/fact.c

The linux utility,which you could use to examine your .o files for comparison of link symbols is nm

nm *.o

somewhat similar to Windows
dumpbin /symbols *.obj

Thank you. You suggestion solved the issue.

Regards

MA

Leave a Comment

Please sign in to add a comment. Not a member? Join today