C++ DLL linking a fortran lib under x64

C++ DLL linking a fortran lib under x64

Hi,

I am working on converting some working 32bits code to x64. I got the Fortran library to compile / link correctly but when I try to link the C++ part, I am getting some unresoved externals within Fortran files. Here are a few examples:

1>EngLF-Lib.lib(lf82.obj) : error LNK2001: unresolved external symbol for_rewind

1>EngLF-Lib.lib(LIRCOD.obj) : error LNK2001: unresolved external symbol for_read_seq_fmt

1>EngLF-Lib.lib(CLBAR.obj) : error LNK2001: unresolved external symbol for_cpstr

1>EngLF-Lib.lib(STARTM.obj) : error LNK2001: unresolved external symbol for_cpystr

1>EngLF-Lib.lib(nrs3.obj) : error LNK2001: unresolved external symbol for_open

Note that in my Fortran project; the only things I changed are the target platform (x64) and the default integer size.

Thank you for your help

Philippe

 

 

 

 

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The missing external symbols are from the Fortran runtime library. Whenever you have a mixed language project, if you call the linker directly or if you use one of the C/C++ compiler drivers to do the linking, they will not know that the Fortran runtime libraries are to be included in the link step. You can take care of the problem by (i) using the Fortran driver, ifort, to do the linking, (ii) specifying the Fortran runtime libraries as additional libraries in the project options in Visual Studio, or (iii) adding a #pragma comment(lib,...) directive to one or more of your C/C++ source files. For details about the directive, see http://support.microsoft.com/kb/153901 .

Here's what I would suggest:

1. Follow the instructions in How do I configure Microsoft Visual C++ for developing mixed Fortran-C applications?

2. Make sure your Fortran library is built with the property Fortran > Libraries > Disable Default Library Search Rules set to "No"

3. Add the path to your Fortran library to the Linker> Additional Dependencies of your C++ project

Steve

Login to leave a comment.