- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
F1C++ 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)"
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
extern "C" void f1 (....)
Otherwise C++ name mangling is applied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your help.
After that others linking problems occur but I manage to solve it when I link the library ifcore and dl.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page