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

C++ DLL linking a fortran lib under x64

philippe_bernier
Beginner
488 Views

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

 

 

 

 

0 Kudos
2 Replies
mecej4
Honored Contributor III
488 Views

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 .

0 Kudos
Steven_L_Intel1
Employee
488 Views

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

0 Kudos
Reply