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

Calling Fortran From C++ (64 bit)

Harvey__Thomas
Beginner
416 Views

I am converting a C++/Fortran application from 32 bit to 64 bit Windows and need to call a Fortran subroutine with no arguments from c++.  This works fine in 32 bit but in 64 bit I receive an error:

LNK2019: unresolved external symbol wtest referenced in function main

The Fortran is linked as a static library and the C++ is obviously the main routine.  I am using defaults for calling methods (which I think is __cdecl under 64 bit).  I have produced the assembly listings and everything looks fine there, ie. both modules are using the same symbol wtest for the Fortran subroutine.  In 32 bit both assembly's prepend an underscore to wtest but it works in that environment.

Using VS 2012 Update 4 and Fortran XE 2015 (Package ID: w_fcompxe_2015.2.179)

Here is the Fortran:

      subroutine WTEST() BIND(C,NAME='wtest')
      return
      end subroutine WTEST

Here is the C++ code:

extern "C" void wtest();

int __cdecl main(int argc, char *argv[])
{
	wtest();
}

I know this topic has been beaten to death over the years and I have looked at/tried many of the suggestions. Again they work in 32 bit but not 64 bit.  I'm sure I am missing something real stupid/obvious so apologies in advance.

Thanks!

So, just before I submit this I try one more thing and now I'm going to answer my own question.  It was real stupid/obvious:  the x64 config puts the Fortran static library in a different folder so I was linking to the wrong thing.  Duh ... maybe this will help someone else.  I don't want to admit to how many hours I've spent on this!

0 Kudos
1 Reply
FortranFan
Honored Contributor III
416 Views

To err is human; to forgive oneself and move on unfazed, a programmer! :-)

0 Kudos
Reply