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

Simple C++ project using static Fortran library fails to link ifconsol.lib

AONym
New Contributor II
1,105 Views

I am testing IFORT integration with VS 17.4.1 under Windows 11.

I've created a simple C++/MFC application which uses Fortran in a static library, LibFort.lib. Here is the build log for the library

Deleting intermediate files and output files for project 'LibFort', configuration 'Debug|x64'.
Compiling with Intel® Fortran Compiler Classic 2021.7.1 [Intel(R) 64]...
ifort /nologo /debug:full /Od /warn:interfaces /module:"x64\Debug\\" /object:"x64\Debug\\" /Fd"x64\Debug\vc170.pdb" /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs /c /Qlocation,link,"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX64\x64" /Qm64 "C:\Users\Superman\source\repos\LibFort\FortranSub1.f90"
Creating library...
Lib /OUT:"x64\Debug\LibFort.lib" /NOLOGO -qm64 "x64\Debug\FortranSub1.obj"

Here is the build of the project

1>------ Rebuild All started: Project: IntelFortranTestIntegration, Configuration: Debug x64 ------
2>------ Rebuild All started: Project: LibFort (IFORT), Configuration: Debug x64 ------
2>Deleting intermediate files and output files for project 'LibFort', configuration 'Debug|x64'.
2>Compiling with Intel® Fortran Compiler Classic 2021.7.1 [Intel(R) 64]...
2>FortranSub1.f90
2>Creating library...
2>
2>Build log written to  "file://C:\Users\Superman\source\repos\LibFort\x64\Debug\BuildLog.htm"
2>LibFort - 0 error(s), 0 warning(s)
1>pch.cpp
1>IntelFortranTestIntegration.cpp
1>IntelFortranTestIntegrationDlg.cpp
1>Generating Code...
1>Searching libraries
1>    Searching C:\Users\Superman\source\repos\LibFort\x64\Debug\LibFort.lib:
...
1>LINK : fatal error LNK1104: cannot open file 'ifconsol.lib'

Here is the source code for the library

MODULE Fortran_Subroutines
    CONTAINS

    SUBROUTINE Sub1
    IMPLICIT NONE
    INTEGER :: i
    REAL(8), DIMENSION(5) :: x
    DO i=1,10
        x(i)= i**2
    END DO
    END SUBROUTINE Sub1
END MODULE Fortran_Subroutines

Why does this module require `ifconsol.lib`, and where is that library, anyway?

0 Kudos
7 Replies
Steve_Lionel
Honored Contributor III
1,073 Views

Configuring Visual Studio for Mixed-Language Applications (intel.com)

 

This hasn't been updated for recent versions, but the instructions are the same, except to use 22 for vv.

Most if not all Fortran objects include a library directive for ifconsol.lib, which is part of the Intel Fortran runtime library.

0 Kudos
AONym
New Contributor II
1,043 Views

Steve -

This indeed looks promising. I was wondering why the Fortran install doesn't do this, till I realized it probably does, BUT, in order to make Fortran work, with VS 17.4.1, you have to 'Repair' VS after the Fortran install, which no doubt remove the Fortran directory settings.

 

Still in the dark as to why a Fortran object that does no I/O and has no main pgm, since it's a static library, should need to be linked to ifconsol.lib. Maybe that library contains some initialization code?

0 Kudos
Steve_Lionel
Honored Contributor III
1,037 Views

The compiler always puts out a reference to ifconsol.lib unless you have told it that you're doing a QuickWin or /winapp compile. I often suggest that libraries be built with the /libdir:noauto option - this tells the compiler to not add default library directives to the object. You are then responsible for making sure the needed libraries get linked in by adding them to the "additional dependencies" list in the executable project.

0 Kudos
AONym
New Contributor II
994 Views

The directions in Configuring Visual Studio for Mixed-Language Applications (intel.com) do not work for me (details below). In addition, I cannot exit VS, despite having done a repair of VS after installing oneApi base and HPC.

I opened a solution which contains two C++ source files, a simple MFC dialog, to be linked to a static Fortran library. Under View / Property Manager / Debug|Win32, I do not see "Microsoft.Cpp.Win32.user", only "Application", "Unicode Support", and "Static Link to MFC" (my solution properties call for linking MFC as a static library).

0 Kudos
Steve_Lionel
Honored Contributor III
980 Views

The issue with not being able to close VS is a known compatibility problem with VS 17.4. You can roll back to 17.3 - see Fortran projects and VS do not close and ICL gives errrors on STD::MAX with VS 2022 17.4 - Intel Communities

As for the library and include paths, VS2019 (and later) removed .user property pages, though if you already had them, they were imported. See how to set up global include path for C++ - Visual Studio Feedback  

Links on that page suggest other ways of adding property pages, but it would probably be easier to just add the folders described to the project property pages (Linker > General > Additional Library Directories for libraries.)

0 Kudos
AONym
New Contributor II
853 Views

I located the file at

`C:\Program Files (x86)\Intel\oneAPI\compiler\2023.0.0\windows \compiler\lib\intel64_win\ifconsol.lib`. I noted that the macros used in the property pages have `$(IFortInstallDir) = C:\Program Files (x86)\Intel\oneAPI\compiler\2023.0.0\windows`.

I tried adding `$(IFortInstallDir)compiler\lib\Intel64_win` to Linker / General / Additional Library Directories. This did not work (same linker error, can't find file). I changed the additional directory to `$(IFORT_COMPILER23)compiler\lib\Intel64_win`, and now I can link without error.

I would still like to find a way to have the appropriate Fortran libraries included in the Linker commands automatically, so I don't have to add them each time, or change them every time the oneAPI/IFORT version changes.

0 Kudos
Steve_Lionel
Honored Contributor III
829 Views

Unfortunately, your use of $(IFORT_COMPILER23) is as close as you'll get to version-independence. There is no other environment variable that will get you the "latest, even across versions".

0 Kudos
Reply