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:
Visual Studio 15 2017 Win64 generator, no Fortran path specified -> Fortran compiler is not detected at all
Visual Studio 15 2017 Win64 generator, path to the Fortran compiler is specified -> Fortran is not able to compile a test program
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
>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.
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.
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 *?
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.
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.
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.
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.