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

What does the IFX compiler add to the subroutine name?

Soniya
Beginner
441 Views

i am trying to call a subroutine from Fortran code using static library in C++ project. 

i am getting linker error - unresolved external symbol gamma_ referenced in function main

 

0 Kudos
3 Replies
Arjen_Markus
Honored Contributor II
433 Views

The subroutine/function name that you use in your code is often decorated in some way, in this case an underscore is appended. This decoration differs per compiler and sometimes even per compiler options. The message is therefore: do not tryto rely on this. Instead use the BIND(C) attribute to make sure the external name is independent of this. BIND(C) is part of the enhanced Fortran-C interfacing that was introduced in Fortran 2003. Something along these lines:

subroutine gamma(x,f) bind(c,name = 'Gamma')
   real, in :: x
   real, out :: f
   ...
end subroutine

With this attribute and the given name the external name would be "Gamma". This is a way to make Fortran names case-sensitive. And you could also declare the arguments to be compatible with C - see the ISO_C_BINDING module - if they are not by default. 

mecej4O
Novice
364 Views

Note that in recent decades Gamma became an intrinsic function in Fortran. If your Fortran library provides another external function with the same name, you have to take a number of steps to ensure that the external function is invoked rather than the intrinsic function. Furthermore, you have to check the types of the arguments and the calling conventions for compatibility.

mecej4O
Novice
226 Views

You may also consider removing the user-provided source code for the now-intrinsic gamma function, unless the old source code is going to be compiled with some no-out-of-date Fortran compiler. You would get better performance and precision by using the vendor provided intrinsic function code.

0 Kudos
Reply