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

error LNK2019: unresolved external symbol' emerge when calling IMSL lib

lu_z_
Beginner
1,858 Views

   Hi, I got a linking error when I tried to call IMSL function (parallel studio xe 2015 + IMSL6.0), which read like

1>imsl.lib(r1int.obj) : error LNK2001: unresolved external symbol  ___kmpc_threadprivate_cached
1>imsls_err.lib(flexlm.obj) : error LNK2001: unresolved external symbol  ___kmpc_critical
1>imsls_err.lib(e1lock.obj) : error LNK2001: unresolved external symbol  ___kmpc_end_critical

  and a lot of similar error message

From https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/285970  I have known that it was likely due to incorrect setting of lib path. However, even I have added the imsl.lib and imsls_err.lib to project>>properties>>linker>>input>>Additional Dependencies. The problem remains. can someone help me to fix this problem

Following is a snippet of problematic code

subroutine sub_tauchen(y,pi,picum,rho,sigma,n,cover_tauchen)
    
    INCLUDE 'link_fnl_static.h'
	!use msimsl  ! need ISML lib already be installed
	use mod_types
    use ANORDF_INT
    !USE NUMERICAL_LIBRARIES
    
	implicit none
    
	integer, intent(in) :: n
	
	real(dp), intent(in) :: rho, sigma, cover_tauchen
	real(dp), dimension (n,n), intent(out) :: pi , picum
	real(dp), dimension (n), intent(out) :: y
		
	integer :: yc, tc, tcc
	
	real(dp) :: sigy, mu, upp, low
	
	! Define the discrete states of the Markov chain
	
	sigy = sigma/sqrt(1.0-rho**2)
	
	y(n) = cover_tauchen*sigy !%(sqrt(n)/sqrt(2.0))*sigy ! good for 0.007, increase later
	y(1) = -y(n)
	
	do yc = 2, n-1
		
		y(yc) = y(1)+(y(n)-y(1))*(yc-1.0)/(n-1.0)
	
	end do
	
	! Compute the transition matrix
	
	do tc = 1,n
		mu = rho*y(tc)
		upp = (y(2)+y(1))/2.0
		upp = (upp-mu)/sigma
		pi(tc,1) = ANORDF(upp)
		low = (y(n)+y(n-1))/2.0
		low = (low-mu)/sigma
		pi(tc,n) = 1.0-ANORDF(low)
		
		do tcc = 2, n-1		
			
			low = (y(tcc-1)+y(tcc))/2.0
			upp = (y(tcc+1)+y(tcc))/2.0
			low = (low-mu)/sigma
			upp = (upp-mu)/sigma
			pi(tc,tcc) = ANORDF(upp)-ANORDF(low)
		
		end do
	end do

	! Compute the CDF of the transition matrix.
	picum(:,1)=pi(:,1)
	do tc = 2,n
		picum(:,tc)=picum(:,tc-1)+pi(:,tc)
	enddo

	open(unit=98,file='Tauchen.txt')
	write(98,*) 'rho, sigma, n'
	write(98,*) rho, sigma, n
	write(98,*) 'Income States'
	write(98,*) y(1:n)
	write(98,*) 'Transition Matrix'
	
	do tc=1,n
		write(98,*) pi(tc,:)
	end do
	
	write(98,*) 'Transition Matrix CDF'
	
	do tc=1,n
		write(98,*) picum(tc,:)
	end do

	close(98)

	open(unit=16,	file='transition.txt', status = 'replace')
	write (16, '(41f20.10)') (pi(i1, :), i1 = 1,n)
	close(16)

	
end subroutine sub_tauchen

 

0 Kudos
9 Replies
Steve_Lionel
Honored Contributor III
1,858 Views

Do one (not both!) of these:

  1. Replace 'link_fnl_static.h' with 'link_fnl_shared.h' (my recommendation)
  2. After that INCLUDE line, add:
    !DEC$ OBJCOMMENT LIB:"libiomp5md.lib"

 

0 Kudos
lu_z_
Beginner
1,857 Views

Steve Lionel (Ret.) wrote:

Do one (not both!) of these:

  1. Replace 'link_fnl_static.h' with 'link_fnl_shared.h' (my recommendation)
  2. After that INCLUDE line, add:
    !DEC$ OBJCOMMENT LIB:"libiomp5md.lib"

 

Thank you for your helpful reply, steve. I added  !DEC$ OBJCOMMENT LIB:"libiomp5md.lib" statement. However, there were some new errors emerged

msvcrt.lib(MSVCR120.dll) : error LNK2005: __time32 already defined in LIBCMT.lib(time.obj) 
LIBCMT.lib(crt0init.obj) : warning LNK4098: defaultlib msvcrt.lib conflicts with use of other libs/NODEFAULTLIB:library
Debug\EGM.exe : fatal error LNK1169 one or more multiply defined symbols found

Moreover, if I change INCLUDE 'link_fnl_static.h' to INCLUDE 'link_fnl_shared.h', there were a lot of Error LNK2019"unresolved external symbol 'symbol' referenced in function" error emerged.

 

0 Kudos
mecej4
Honored Contributor III
1,857 Views

There are too many cooks in the kitchen: if you add "include 'link_fnl_shared.h'" in your source code, and you also specified imsl.lib in the build configuration, you introduced an inconsistency, since imsl.lib is a static library, whose shared library counterpart is imsl_dll.lib.

Follow the instructions at https://software.intel.com/en-us/articles/installing-and-using-the-imsl-libraries .

0 Kudos
Steve_Lionel
Honored Contributor III
1,857 Views

Can you show those errors?

For the first issue, you have "mixed C library syndrome". Let's see if we can work out the issues with using link_fnl_shared.h.

0 Kudos
lu_z_
Beginner
1,858 Views

Steve Lionel (Ret.) wrote:

Can you show those errors?

For the first issue, you have "mixed C library syndrome". Let's see if we can work out the issues with using link_fnl_shared.h.

Since I use the Chinese version of Visual studio, the error message is mixed up with Chinese characters, but the meaning was clear

1>sub_tauchen.obj : error LNK2019: unsolved external symbol  @_RTC_CheckStackVars@8,该符号在函数 _SUB_TAUCHEN 中被引用
1>sub_myinterp1.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>sub_value.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>main.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>sub_eulerequationerror.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>sub_kendogenousnewton.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>sub_myinterp.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>mod_types.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>mod_common_var.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>sub_simul.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>sub_grid_generation.obj : error LNK2001: unsolved external symbol  @_RTC_CheckStackVars@8
1>sub_myinterp.obj : error LNK2001: unsolved external symbol  __RTC_CheckEsp
1>sub_myinterp1.obj : error LNK2001: unsolved external symbol  __RTC_CheckEsp
1>mod_types.obj : error LNK2019: unsolved external symbol  __RTC_CheckEsp,该符号在函数 _MOD_TYPES. 中被引用
1>mod_common_var.obj : error LNK2001: unsolved external symbol  __RTC_CheckEsp
1>sub_grid_generation.obj : error LNK2001: unsolved external symbol  __RTC_CheckEsp
1>sub_kendogenousnewton.obj : error LNK2001: unsolved external symbol  __RTC_CheckEsp
1>sub_value.obj : error LNK2019: unsolved external symbol  __alloca_probe,该符号在函数 _SUB_VALUE 中被引用
1>sub_simul.obj : error LNK2001: unsolved external symbol  __alloca_probe
1>main.obj : error LNK2001: unsolved external symbol  __alloca_probe
1>sub_eulerequationerror.obj : error LNK2001: unsolved external symbol  __alloca_probe
1>sub_tauchen.obj : error LNK2001: unsolved external symbol  __alloca_probe
1>sub_value.obj : error LNK2001: unsolved external symbol  __fltused
1>sub_kendogenousnewton.obj : error LNK2001: unsolved external symbol  __fltused
1>sub_myinterp.obj : error LNK2001: unsolved external symbol  __fltused
1>sub_tauchen.obj : error LNK2001: unsolved external symbol  __fltused
1>sub_myinterp1.obj : error LNK2001: unsolved external symbol  __fltused
1>sub_simul.obj : error LNK2001: unsolved external symbol  __fltused
1>sub_grid_generation.obj : error LNK2001: unsolved external symbol  __fltused
1>main.obj : error LNK2019: unsolved external symbol  __fltused,该符号在函数 _MAIN__ 中被引用
1>sub_eulerequationerror.obj : error LNK2001: unsolved external symbol  __fltused
1>LINK : error LNK2001: unsolved external symbol  _mainCRTStartup
1>Debug\EGM.exe : fatal error LNK1120: 5 个无法解析的外部命令

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,858 Views

I wonder if you have somehow disabled linking to the Microsoft C++ libraries. Would you please attach a ZIP of the .vfproj and .vcxproj files in your application's Visual Studio solution?

0 Kudos
lu_z_
Beginner
1,858 Views

Steve Lionel (Ret.) wrote:

I wonder if you have somehow disabled linking to the Microsoft C++ libraries. Would you please attach a ZIP of the .vfproj and .vcxproj files in your application's Visual Studio solution?

Of course

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,858 Views

Thanks. In your Fortran project properties, go to Linker > Input. Clear the entry you have for "Ignore specific library". You have this set only in the Debug configuration. You have it set to ignore MSVCRTD.lib, which prevents the linker from seeing the MSVC library entries listed in the error messages.

0 Kudos
lu_z_
Beginner
1,858 Views

  Great, it works, thank you @steve and @mecej4 for your patience and help

0 Kudos
Reply