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

Can't link fortran files

Malik_M_
Beginner
455 Views

Hello,

Trying to compile and link fortran files to the CPP project, linked as an static library file(CPP calls FORTRAN) will case a following errors,

Undefined symbols for architecture x86_64:
  "_for_write_seq_lis", referenced from:
      _coeff in liblib_rastres.a(coeff.o)
  "_for_write_seq_lis_xmit", referenced from:
      _coeff in liblib_rastres.a(coeff.o)
ld: symbol(s) not found for architecture x86_64

Calling one of the fortran library functions from main.cpp looks like an external C functions,

 extern "C"
{
  void coeff(double[],double[],double[],double[],double[],double[],double[],double[],double[],double[],double[]
  ,double[],double[],double[],double[],double[],double[],int**,double[],double[],double[],int);
}

There is no problems with my project external names, when linked. However, there is  an internal Intel library linking error.

My OS is OSX 10.13.14, IDE: Netbeans 8.2, Compiler: Intel Parallel Studio (Composer) 2018 with Intel cpp/fortran compilers.

NETBEANS CPP PROJECT:  QT application with Intel CPP.

NETBEANS FORTRAN PROJECT: Static library with Intel Fortran.

FORTRAN TEXT:

 subroutine coeff(V,a1,b1,c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4, Iuzl3d, X3d, Y3d, Z3d, N_el) BIND(C,name="coeff")
 use, intrinsic :: ISO_C_BINDING
 implicit none
 integer,  parameter  :: N = 3, M = 4
 integer(kind=C_INT),intent(in) :: N_el 
 integer(kind=C_INT),intent(in) :: Iuzl3d(10,N_el)
 real(kind=C_DOUBLE),intent(in) :: X3d(N_el), Y3d(N_el), Z3d(N_el)
 real(kind=C_DOUBLE),intent(out):: V(N_el),a1(N_el),b1(N_el),c1(N_el),d1(N_el),a2(N_el),b2(N_el),c2(N_el),d2(N_el),a3(N_el)
 real(kind=C_DOUBLE),intent(out):: b3(N_el),c3(N_el),d3(N_el), a4(N_el), b4(N_el), c4(N_el), d4(N_el)
!
 integer(kind=C_INT)            :: i,k
 real(kind=C_DOUBLE)            :: aa(N,N)
 real(kind=C_DOUBLE)            :: x(M),y(M),z(M)
 real(kind=C_DOUBLE),parameter  :: zero=0.0_C_DOUBLE, one = 1.0_C_DOUBLE, six = 6.0_C_DOUBLE 
 interface
    function detf(aa)
    double precision                :: detf
    double precision, intent(in)    :: aa(3,3)
    end function detf
 end interface    
!
 do i=1,N_el
    x(1:M)=X3d(Iuzl3d(1:M,i))
    y(1:M)=Y3d(Iuzl3d(1:M,i))
    z(1:M)=Z3d(Iuzl3d(1:M,i))

.....

        d1(i) = detf(aa)

....... 

 enddo

 function detf(aa)
 implicit none    
 double precision, intent(in) :: aa(3,3)
 double precision :: detf, det
 det  = aa(1,1)*aa(2,2)*aa(3,3)-aa(1,1)*aa(2,3)*aa(3,2)-aa(1,2)*aa(2,1)*aa(3,3)
 detf = det + aa(1,2)*aa(2,3)*aa(3,1)+aa(1,3)*aa(2,1)*aa(3,2)-aa(1,3)*aa(2,2)*aa(3,1)
 end function detf

Thank you for any help,

Malik

 

 

 

0 Kudos
3 Replies
Eugene_E_Intel
Employee
455 Views

Hello,

Since you generated Fortran static library, it only has your Fortran code and not any other supporting library code that your Fortran code needs to function.

Suggestion: try linking your resulting executable using "ifort": it will know, what other libraries need to be added at the link stage to satisfy the dependencies of your code.  Alternatively, you could compile your Fortran code into a dynamic library (.so), in which case all the Fortran code dependencies will be satisfied at .so link time.

Thank you,

--Eugene

 

0 Kudos
Malik_M_
Beginner
455 Views

Thank you Eugene, I will try...

Malik.

0 Kudos
Malik_M_
Beginner
455 Views

Thank you again Eugene, it works with ifort -staticlib tool!

Malik. 

0 Kudos
Reply