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

What does the IFX compiler add to the subroutine name?

Soniya
Beginner
1,666 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
1 Solution
Arjen_Markus
Honored Contributor II
1,658 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. 

View solution in original post

7 Replies
Arjen_Markus
Honored Contributor II
1,659 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
1,589 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
1,451 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
JohnNichols
Valued Contributor III
844 Views

@mecej0  Welcome back, it was a poorer forum without your input, as these notes show.  

0 Kudos
JohnNichols
Valued Contributor III
843 Views

I still have my Complex Analysis Textbook from 1977, and if I remember correctly complex analysis was the only math topic that I got a good grade in at ANU, although the average grade was a pass, they  marked very hard. 

0 Kudos
mecej4O
Novice
421 Views

If, for some reason, you want old-style (Fortran 77) source for the gamma function, note that the public-domain SLATEC library from Sandia National Laboratory contains source code for single and double precision versions of the gamma function (and  complex versions, as well).

0 Kudos
mecej4O
Novice
420 Views
0 Kudos
Reply