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

LNK2019 error - Fortran calling C++ library

tkibedi
Beginner
1,055 Views

I try to link an old Fortran legacy code with a C++ library, developed for CVF6.6. Using the mixed language sample to call C++ library from Fortran, I modified the interface declaration, but I could not resolve the LNK2019 error. I attach the Fortran source, the lib and dll file obtained as part of the Poisson Superfish package.

Unfortunately I do not have the source code for the C++ library. Any help would be appreciated to resolve the problem.

 

 

0 Kudos
6 Replies
Steve_Lionel
Honored Contributor III
1,055 Views

It always helps, when asking for help on an error, to show the exact and complete text of the error, rather than just referring to it by number. None of us have memorized all the error numbers, and LNK2019 is extremely generic.

The library assumes CVF calling convention, which is STDCALL. The simplest way to deal with this is to add the line:

!DEC$ ATTRIBUTES CVF :: INTERP

after the IMPORT line in your interface for INTERP. (I assume you are using a reasonably current version of Intel Fortran. If you're using one from 2011 or so, I don't want to hear about it.)

If this doesn't resolve the issue, please ZIP the buildlog.htm and attach that to a reply here.

0 Kudos
tkibedi
Beginner
1,054 Views

Thanks Steve. I am using the VS2015 and the latest Intel Fortran Compiler (19.0.4.228). Attached is the bulldog.htm file.

 

Tibor

0 Kudos
tkibedi
Beginner
1,054 Views

I forget to add, that inserting the 

!DEC$ ATTRIBUTES CVF :: INTERP

did not solve the problem. 

 

Tibor

0 Kudos
Steve_Lionel
Honored Contributor III
1,054 Views

Oh, I missed that you had BIND(C) at the end of the declaration of INTERP. Try this:

  Interface
    Integer(kind=4) function INTERP(SolutionFile, Xvalue, Yvalue, Solution, Xcomponent, Ycomponent, DBYDY, DBYDX, DBXDY)  bind(C,NAME="INTERP")
    IMPORT ! Use declarations from host
!DEC$ ATTRIBUTES STDCALL :: INTERP
      CHARACTER(kind=C_CHAR), Dimension(*), Intent(IN)      :: SolutionFile
      Real (kind=8),  Intent(IN)        :: Xvalue, Yvalue
      Real (Kind=8),        Intent(OUT)       :: Solution,  Xcomponent, Ycomponent
      Real (Kind=8),        Intent(OUT)       :: DBYDY, DBYDX, DBXDY
    End Function INTERP
  End Interface

This should link, but I note that your program doesn't NUL-terminate SolutionFile and the library is not expecting a length to be passed (9 arguments at 4 bytes each corresponds to the @36 suffix), so I am not sure how it determines the character length.

0 Kudos
FortranFan
Honored Contributor II
1,054 Views

tkibedi wrote:

I forget to add, that inserting the 

!DEC$ ATTRIBUTES CVF :: INTERP

did not solve the problem. 

 

Tibor

Once you get past the linking error, you can take a closer look at your code: did you mean to declare the 'SolutionFile' as a scalar variable in line 17 with a default length which is 1?

By the way, from a portability viewpoint for interoperable code, you may want to use the defined kinds in 'ISO_C_BINDING' intrinsic module of c_int and c_double rather than hard-wired ones of 4, 8 which don't have the same meaning on different compilers.  Also, you may want to consider the BLOCK with EXIT construct (https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-block) which is preferable to DO intended to used as one-pass.

0 Kudos
tkibedi
Beginner
1,054 Views

Thanks for the suggestions. I compiled and linked the attached file (CVF_Interp.f90) and it works now. I used MS VS 2015 and Intel XE 2019 compiler on a Win10 machine. 

0 Kudos
Reply