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

NOL3
NOL3 used Ask the Experts™
on
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....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
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

Author

Commented:
>> 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)?
Top Expert 2016
Commented:
Dumb question: how do i do that?
if using visual studio fortran compiler and it allowed you to change to 64-bit, you should be able to find those libraries below of the visual studio  fortran installation path. unfortunately, there is no easy way to find out whether a .lib file is 32-bit or 64-bit. but it is rather sure that the folder name or file name provides this information. since you can't mix 32-bit modules with 64-bit ones, you should get at least an error if you choose the wrong ones and try to build your c wrapper.

it could be possible that you have to run visual studio setup again in order to get all platform specific stuff. you may search in MSDN for your missing functions or search for "64 bit fortran libaries". the functions you were missing sound to be system functions. so you also could try to get a sample project of a 64-bit fortran program and look into the linker input properties (or the build command) to find out which libraries were used.

Sara
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.

Author

Commented:
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!!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial