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

Link Problem between Ifort compiled program and g++

sphost
Beginner
376 Views

Hi,

I work on a C++ project and we have to integrate some mathematical Model written in Fortran.

I compiled this Model with ifort and made an .a file.

I tried to call this model in my C++ code but during the linkof the .a library with g++ an error occured "Undefined reference to" my Fortran function.

Do I have to put specific option with ifort and g++in order to able to link correctly ?

Thanks in advance for your answers.

Sample code test below :

Fortran Code :

subroutine

F1(B, D, TAILLE_D) BIND(C, NAME="f1")

use, intrinsic :: ISO_C_BINDING

implicit none

real(C_DOUBLE), intent(inout) :: B

real(C_DOUBLE), dimension(*), intent(in) :: D

integer(kind=C_LONG), VALUE :: TAILLE_D

print *, "B=", B, "D(",TAILLE_D,")=", D(TAILLE_D)

end subroutine

F1

C++ Code

void f1( double *b, double d[], long taille_d );

main()

{

double beta = 378.0 ;

double delta[] = { 17., 12.3, 3.14, 2.718, 0.56,

22.67, 25.8, 89., 76.5, 80. } ;

long taille_delta = sizeof delta / sizeof delta[0] ;

f1( β, delta, taille_delta ) ;

return 0;

}

With this test, I obtain : "Undefined reference to `f1(double*, double*, long)"

0 Kudos
2 Replies
Steven_L_Intel1
Employee
376 Views
In your C++ code, you need to write:

extern "C" void f1 (....)

Otherwise C++ name mangling is applied.
0 Kudos
sphost
Beginner
376 Views

Thanks for your help.

After that others linking problems occur but I manage to solve it when I link the library ifcore and dl.

0 Kudos
Reply