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_somth ing..... 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(S omeObject1 .obj) : error LNK2001: unresolved external symbol for_check_mult_overflow64
1>MyFortranLibrary_lib.lib (SomeObjec t2.obj) : error LNK2001: unresolved external symbol for_check_mult_overflow64
1>MyFortranLibrary_lib.lib (SomeObjec t1.obj) : error LNK2001: unresolved external symbol for_alloc_allocatable
1>MyFortranLibrary_lib.lib (SomeObjec t2.obj) : error LNK2001: unresolved external symbol for_alloc_allocatable
1>MyFortranLibrary_lib.lib (SomeObjec t1.obj) : error LNK2001: unresolved external symbol for_dealloc_allocatable
1>MyFortranLibrary_lib.lib (SomeObjec t3.obj) : error LNK2001: unresolved external symbol for_write_seq_fmt
1>MyFortranLibrary_lib.lib (SomeObjec t4.obj) : error LNK2001: unresolved external symbol for_write_seq_fmt
1>MyFortranLibrary_lib.lib (SomeObjec t5.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....
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_somth
Here's a sample of the these LNK errors:
MyFortranLibrary_lib.lib(S
1>MyFortranLibrary_lib.lib
1>MyFortranLibrary_lib.lib
1>MyFortranLibrary_lib.lib
1>MyFortranLibrary_lib.lib
1>MyFortranLibrary_lib.lib
1>MyFortranLibrary_lib.lib
1>MyFortranLibrary_lib.lib
Any help in troubleshooting would be GREATLY APPRECIATED!!!!! I'm seriously racking my brain on this one....
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)?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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!!!!
Thanks again!!!!
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