How to set up compilation with Intel Fortran compiler on Windows correctly?

Hello,
I’m trying to build my C/C++/Fortran project both on Ubuntu and Windows10. The compilation on Linux posses no problems, but Intel Fortran compiler on Windows seems to cause great complications for CMake.

I’ve tried 3 configurations so far:

  1. Visual Studio 15 2017 Win64 generator, no Fortran path specified -> Fortran compiler is not detected at all
  2. Visual Studio 15 2017 Win64 generator, path to the Fortran compiler is specified -> Fortran is not able to compile a test program
  3. NMake Makefiles generator -> Fortran compiler is detected successfully, but compilation fails shortly afterwards with some syntax error

I’m using Visual Studio 2017 and Intel Compiler 19.0 on Windows 10 in this case.

So, what is the “official” way to use CMake on Windows together with cl compiler provided by Visual Studio and ifort compiler provided by Intel Parallel Studio XE? I would prefer solution using Visual Studio Generator for my project, if possible.

Thank you very much for your advice,
Martin


Full Compilation Outputs

Visual Studio 15 2017 Win64 generator, no Fortran path specified

https://pastebin.com/quCgtYx3


Visual Studio 15 2017 Win64 generator, path to the Fortran compiler is specified

https://pastebin.com/kHpRcBfD


NMake Makefiles generator

https://pastebin.com/pj7cetHk

Both (1) and (3) are expected to work.

I’m not able to reproduce this failure:

>cmake --version
cmake version 3.16.3
...

>type ..\CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(TryFortran Fortran)

>cmake .. -G "Visual Studio 15 2017 Win64"
...
-- The Fortran compiler identification is Intel 19.0.5.20190815
...
-- Check for working Fortran compiler: C:/Program Files (x86)/Intel/SWTools/compilers_and_libraries_2019/windows/bin/intel64/ifort.exe  -- works

Be sure to check the CMakeFiles/CMakeError.log mentioned in CMake’s output.

Also, be sure you have Intel 2019 update 5 or above. Otherwise a bug in the Intel Compiler Visual Studio Integration prevents it from working. See CMake Issue 19691 for details of that problem.

@brad.king ,
I have Intel 2019 update 5, so that one should be ok. Also, I had a look at the CMakeError.log, but unfortunately, it’s really brief:

Compiling the Fortran compiler identification source file "CMakeFortranCompilerId.F" failed.
Compiler:  
Build flags: 
Id flags:  

The output was:
The system cannot find the file specified


Compiling the Fortran compiler identification source file "CMakeFortranCompilerId.F" failed.
Compiler:  
Build flags: 
Id flags:  

The output was:
The system cannot find the file specified

This happened with the first configuration, i.e. Visual Studio 15 2017 Win64 Makefile Generator. The one difference I can see is, that my project really uses C and C++ too, so I use project(myLib C CXX Fortran) and not only Fortran language for this.

Also, CMakeFortranCompilerID.F is located at CMakeFiles\3.16-rc3\CompilerIdFortran and its full contents are here:

https://pastebin.com/aBspiUp6

Also, you can find the whole folder together with CMakeCache.txt here: https://uloz.to/file/t9KoZwAZ7pPm/build-zip

Check your Visual studio integration (in Visual Studio: Tools > Options > Intel Compilers and Tools > Visual Fortran > Compilers) whether it’s pointing to the correct Fortran installation. Also check that the Fortran compiler is able to obtain its license.

These are two things that often cause Fortran to fail to work for me.

CMakeFiles\3.16-rc3\CompilerIdFortran

Where did you get that CMake? What is cmake --version’s output?

-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x64/cl.exe -- works

That looks like the Visual Studio Build Tools rather than a full VS. I’ve never tried the Intel Fortran Visual Studio integration with that version. Do you have a c:\Program Files (x86)\Microsoft Visual Studio\2017\*\Common7\IDE\devenv.com file for any value of *?

Thank you both!

cmake 3.16-rc3 was downloaded from the official webpage, if I’m not mistaken. So, here’s what I tried now:

  1. I installed newer cmake v3.16.3. - still not working
  2. I installed Visual Studio 2017, because I was really using just VS2017 Build Tools. - still not working
  3. Then I removed Built Tools and left only full Visual Studio on the pc. - working

So, CMake has problems, when Intel Fortran compiler is connected to VS Build Tools instead of full VS.

Once again, thank you both very much!

1 Like

For what it is worth we use Intel Fortran v19 with Visual Studio 2017 and NMake Makefiles to compile our codes. We export the FC environment variable before we start the first configure with CMake and it just seems to work.

https://my.cdash.org/buildSummary.php?buildid=1765288

So I get CMake to detect the Fortran compiler, but when it generates the dependency list in the VS project it sets all of the Fortran and C++ targets to be ignored.

VS 2019, Intel Fortran compiler.

I am building them as part of an OBJECT library that has C, CXX, and Fortran sources.

I have all of the OBJECTS as dependencies to the main library target which is a shared library, which should force it to build all of the source inputs.

Any ideas?

library that has C, CXX, and Fortran sources.

Visual Studio + Intel Fortran do not support having both C/C++ and Fortran sources within a single target. That is a limitation of the tooling, not CMake. In order to support building with that toolset you need to put Fortran sources in a separate target.

1 Like

Thanks! I am not normally a Windows dev so this has been extremely frustrating. You have just saved the day!

I’m not sure I ever would have worked this out without your help, just needed to switch compiler from Build Tools 2017 to Professional 2017. Bravo & thanks.