Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

LNK2019 error - Fortran calling C++ library

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
Highlighted
Black Belt

It always helps, when asking

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.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner

Thanks Steve. I am using the

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
Highlighted
Beginner

I forget to add, that

I forget to add, that inserting the 

!DEC$ ATTRIBUTES CVF :: INTERP

did not solve the problem. 

 

Tibor

0 Kudos
Highlighted
Black Belt

Oh, I missed that you had

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.

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Valued Contributor III

Quote:tkibedi wrote:

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
Highlighted
Beginner

Thanks for the suggestions. I

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