Link to home
Start Free TrialLog in
Avatar of NOL3
NOL3

asked on

Error LNK2001: Unresolved external symbol when calling a FORTRAN subroutine in a FORTRAN 64-bit library from a 64-bit C Wrapper

I have a C wrapper that has always been 32-bit.  It calls a FORTRAN subroutine. This FORTRAN subroutine is in a FORTRAN library (MyFortranLibrary_lib.lib).  This FORTRAN library file has also always been 32-bit. Everything has always worked fine.  However, I have recently changed both the FORTRAN library and the C Wrapper from 32-bit to 64-bit.  I have done this by simply changing the "Active Solution Platform" setting in visual studio from "win32" to "x64" for the C Wrapper and the corresponding setting in the FORTRAN library TO x64. The FORTRAN library compiles fine, without error.

The problem is with the C Wrapper.  When I compile the C Wrapper (and thus try to link it to this 64-bit FORTRAN library), i get A LOT of errors of type "error LNK2001: unresolved external symbol for _something_something_somthing..... So it would appear that there is something further I must do to make things "play nice" between the C Wrapper and FORTRAN library, in the 64-bit world.

Here's a sample of the these LNK errors:

MyFortranLibrary_lib.lib(SomeObject1.obj) : error LNK2001: unresolved external symbol for_check_mult_overflow64
1>MyFortranLibrary_lib.lib(SomeObject2.obj) : error LNK2001: unresolved external symbol for_check_mult_overflow64
1>MyFortranLibrary_lib.lib(SomeObject1.obj) : error LNK2001: unresolved external symbol for_alloc_allocatable
1>MyFortranLibrary_lib.lib(SomeObject2.obj) : error LNK2001: unresolved external symbol for_alloc_allocatable
1>MyFortranLibrary_lib.lib(SomeObject1.obj) : error LNK2001: unresolved external symbol for_dealloc_allocatable
1>MyFortranLibrary_lib.lib(SomeObject3.obj) : error LNK2001: unresolved external symbol for_write_seq_fmt
1>MyFortranLibrary_lib.lib(SomeObject4.obj) : error LNK2001: unresolved external symbol for_write_seq_fmt
1>MyFortranLibrary_lib.lib(SomeObject5.obj) : error LNK2001: unresolved external symbol for_write_seq_fmt

Any help in troubleshooting would be GREATLY APPRECIATED!!!!! I'm seriously racking my brain on this one....
Avatar of sarabande
sarabande
Flag of Luxembourg image

it seems to me that the fortran library is not complete. some library functions still are referencing to 32-bit system functions.

the problem is that the fortran library is not an executable or a dll but simply a collection of object modules. therefore by building the fortran library there is no check on unresolved externals.

you would need a 64-bit fortran library that contains the missing functions. then you could add this library to the linker input libraries of the c wrapper. the original function names are without the leading underline.

Sara
Avatar of NOL3
NOL3

ASKER

>> you would need a 64-bit fortran library that contains the missing functions.

Dumb question: how do i do that? :) Is it a matter of going into the project settings in the FORTRAN library and adding a reference to a 64-bit library of FORTRAN framework/system functions?  Or do I need to change the FORTRAN code itself in my library by replacing the 32-bit versions of these functions with 64-bit versions (as would be the typical process of replacing deprecated functions when migrating to, say, a newer version of Visual Studio)?
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I call Fortran90 from C or C++. I have to make the F90 function names all lower cases followed by an underscore (e.g., for_alloc_allocatable_). The arguments have to be pointers. For example, if I want to pass in a literal number 2, then I have to create a variable, say, int TWO = 2, and pass in &TWO, to make it a pointer. I don't think I had to do anything special with passing in arrays (other than keeping in mind row-major/column-major differences, and starting index 0 vs 1).

But rules may differ on different platforms. I am using Intel Compiler circa 2012 on RHEL 6.3/5/7.
You may specify your environment and may get more help from experts.
Avatar of NOL3

ASKER

Thanks Sara!  Your answer caused me to search the project folder for the C wrapper.  Turns out, there were several 32-bit library files in this folder that were a) not necessary for the 64-bit build, and b) were messing up the ability of the 64-bit build to compile properly.

Thanks again!!!!