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

EXTERNAL statement gives a LNK2001 error

kirbychapman
Beginner
790 Views

The code below is part of a DLL. I call the functions from VBA in Excel.

I have a function that employs the DZBREN root finding IMSL routine. The code follows at the end of this description. THe problem is with the function name that is declared in the EXTERNAL statement (Note: in the code below i have the EXTERNAL statement commented out, as well as the DZBREN routine). When i try to compile the code with the EXTERNAL statement not commented out, i get the LNK error 2001: unresolved external symbol _TFROMHABSERRORFNC. I'm pretty sure i need to declare it EXTERNAL to get the DZBREN routine to work. WHen the DZBREN routine is uncommented, the whole thing crashes

THese functions are contained in a MODULE, just in case that matters. Also, I know that the result of DZBREN is Tb, but I was returning Ta as a debugging measure.

Can someone help me figure this out? Seems simple enough, but i'm beginning to think i'm not smart enough even for simple things...


[fxfortran]      real (8) function TfromHabs_fnc(h,X) 
C  h  Gas enthalpy (kJ/kg)
C  X  Array containing mixture mol fractions
C  TfromHass_fnc  returned temperature (K) corresponding to h
      !dec$ attributes dllexport :: TfromHabs_fnc
      !dec$ attributes stdcall, REFERENCE, alias :'TFROMHABS_F' :: TfromHabs_fnc
      USE MolecularWeights
	implicit none
	include 'Common_Gases.for'
	real(8) h, X(11),Xpassed(11), hPassed
	real (8) Fraction, Ta, Tb
	logical bContinue
	common/PassTfromHasbErrorFnc/hPassed, Xpassed
C	External TfromHabsErrorFnc
	Xpassed=X
	hPassed = h
	Tb = 4000.0
	Fraction = 1.0
	bContinue = .FALSE.
	do while (.not.bContinue)
	  Fraction =Fraction*0.9
	  if (Tb*Fraction.LT.220.0) then
	      TfromHabs_fnc = -999.0
	      return
	  endif
	  if (TfromHabsErrorFnc(Tb)*TfromHabsErrorFnc(Tb*Fraction).lt.0.0) then
	      bContinue = .TRUE.
	  Endif
      end do
      Ta = Tb * Fraction
      
   !   call DZBREN(TfromHabsErrorFnc, 0.0, 0.001, Ta, Tb, 100)
      
      TfromHabs_fnc = Ta
      
      
      return
      end function TfromHabs_fnc
      
      real (8) function TfromHabsErrorFnc(T) 
C  h  Gas enthalpy (kJ/kg)
C  X  Array containing mixture mol fractions
C  TfromHass_fnc  returned temperature (K) corresponding to h
	implicit none
	include 'Common_Gases.for'
	common/PassTfromHasbErrorFnc/hPassed, Xpassed
	real(8) T,hPassed, Xpassed(11)
	TfromHabsErrorFnc=hPassed - habs_fnc(T,Xpassed)
      return
      end function TfromHabsErrorFnc
[/fxfortran]
0 Kudos
3 Replies
Steven_L_Intel1
Employee
790 Views
Because these functions are in a module, the EXTERNAL should not be used, as that indicates that the function is NOT in the module.

Have you debugged this - set breakpoints in the function and see where it dies? What compiler options are you using? You must make sure you are not using /iface:cvf.
0 Kudos
kirbychapman
Beginner
790 Views
Thanks, Steve -- I am new at using MODULES, so that helps a lot to understand the EXTERNAL wrt to the MODULE.

On breakpoints, i have not been successful at adding them to a DLL and getting it to work. I also turned off the /iface:cvf long ago (I think because of a suggestion you provided to someone else).

Can you direct me to a good spot on how to set up a DLL for debugging? If i did actually learn how to do that, I would save an immense amount of time -- Duh...

Following are what i think are the compiler options (I copied this from the command line option). I happened to have it set to release, but i have also attempted a debug version without success in debugging.

/nologo /I"C:\Program Files (x86)\VNI\imsl\fnl600\IA32\include\dll" /gen-interfaces /extend_source:132 /Qopenmp /warn:interfaces /fpconstant /module:"Release\" /object:"Release\" /libs:static /threads /c
0 Kudos
Steven_L_Intel1
Employee
790 Views
The Debug configuration should set up everything you need.
0 Kudos
Reply