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

undefined reference to '_QSORT'

HaoranZhou
Beginner
1,344 Views

Hi all,

Recently I'm trying to compile an in-house solver from Windows to Linux. Firstly, I successfully installed Intel Fortran and mkl. However, something is wrong with Qsort_Element_Types when compiling in Linux. The message is :

2022-01-04 15-01-33 的屏幕截图.png

I used Qsort_Element_Types as follow:

 

!****************************************************************************
!     功能: 对结构体进行排序,调用Intel库函数      
!**************************************************************************** 	
	  Subroutine Qsort_Cell_Faces

	  Use OpenFoam,  ONLY: Cell_Faces
	  Use,Intrinsic :: Iso_C_Binding, ONLY : C_Size_T
      Use Ifport       ! To Get Qsort
      Use Share_Type   

      Interface
         Subroutine Qsort_Element_Types(Array, Len, Isize, Comp)
         Use, Intrinsic :: Iso_C_Binding, Only:C_Size_T
         Use Share_Type
         Type(Element_Type) Array(Len)
         Integer(C_Size_T) Len, Isize
         Integer(2), External :: Comp

         !DIR$ IF DEFINED(_WIN64)
         !DIR$ ATTRIBUTES ALIAS: 'QSORT'  :: QSORT_element_types
         !DIR$ ELSE
		 !DIR$ ATTRIBUTES ALIAS: '_QSORT' :: QSORT_element_types
         !DIR$ ENDIF			
         End Subroutine Qsort_Element_Types
	  End Interface

	  Integer Lines

      Type(Element_Type),Allocatable :: C(:)	  
	  Integer, External  :: Cmp_Function
      Integer (C_Size_T) :: Size_Of_Element, Size_Of_Array
	  Integer I

	  
	  Lines=Size(Cell_Faces,1)
	  Allocate(C(Lines))
	  
	  ! 数组--派生(结构体)
	  Do I=1,Lines
         C(I)%Elem_N = Cell_Faces(I,1)
	     C(I)%Face_N = Cell_Faces(I,2)
	  End Do
	  
	  Size_Of_Array   = Size(C)     
      Size_Of_Element = Sizeof(C(1))   
	  
	  Call Qsort_Element_Types(C, Size_Of_Array, Size_Of_Element, Cmp_Function)   ! 结构体排序
	  
	  ! 派生(结构体)--数组
	  Do I=1,Lines
         Cell_Faces(I,1)= C(I)%Elem_N
	     Cell_Faces(I,2)= C(I)%Face_N   
	  End Do
	  
	  Return
	  End Subroutine
	
	
	  Function Cmp_Function(C1, C2)
      Use Share_Type

      Implicit None

      Type(Element_Type), Intent(In) :: C1 
      Type(Element_Type), Intent(In) :: C2 

      ! Function Result:
      Integer :: Cmp_Function

      Cmp_Function=C1%Elem_N-C2%Elem_N
 
	  End Function

 

 How to solve this problem? Any suggestions will be appreciated!

0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
1,273 Views

You're welcome ;). Such constructions were necessary in the past, before we had Fortran 2003's Fortrna-C interfacing facilities, but luckily now we can leave it to the compiler in many cases to get it right.

View solution in original post

3 Replies
Arjen_Markus
Honored Contributor I
1,326 Views

Try without the !DIR ALIAS for non-Windows platforms. I tried a small program without that and it simply worked. My guess is that it is also not required on Windows - the IPFORT module ought to take care of that and you can simply use:

 

use ifport, only: QSORT_element_types => QSORT

0 Kudos
HaoranZhou
Beginner
1,296 Views

Hi Arjen,

Your suggestion successfully solves my problem. It finally works!

Thanks for your help!

 

0 Kudos
Arjen_Markus
Honored Contributor I
1,274 Views

You're welcome ;). Such constructions were necessary in the past, before we had Fortran 2003's Fortrna-C interfacing facilities, but luckily now we can leave it to the compiler in many cases to get it right.

Reply