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

**URL:** https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532
**Category:** Usage
**Tags:** os:windows, lang:fortran
**Created:** [January 21, 2020, 6:45pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532 "2020-01-21T18:45:50Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![MartinBeseda](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@MartinBeseda](https://discourse.cmake.org/u/MartinBeseda)
#### Post date: [January 21, 2020, 6:45pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/1 "2020-01-21T18:45:50Z")

</div>

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](https://pastebin.com/quCgtYx3)

* * *

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

[https://pastebin.com/kHpRcBfD](https://pastebin.com/kHpRcBfD)

* * *

### `NMake Makefiles` generator

[https://pastebin.com/pj7cetHk](https://pastebin.com/pj7cetHk)

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [January 21, 2020, 7:20pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/2 "2020-01-21T19:20:37Z")

</div>

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

I’m not able to reproduce this failure:

```nohighlight
>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](https://gitlab.kitware.com/cmake/cmake/issues/19691) for details of that problem.

---

<div class="post-metadata">

### Author: ![MartinBeseda](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@MartinBeseda](https://discourse.cmake.org/u/MartinBeseda)
#### Post date: [January 21, 2020, 8:33pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/3 "2020-01-21T20:33:56Z")

</div>

@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:

```auto
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.

---

<div class="post-metadata">

### Author: ![MartinBeseda](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@MartinBeseda](https://discourse.cmake.org/u/MartinBeseda)
#### Post date: [January 21, 2020, 9:09pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/4 "2020-01-21T21:09:29Z")

</div>

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

[https://pastebin.com/aBspiUp6](https://pastebin.com/aBspiUp6)

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

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 22, 2020, 1:50pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/5 "2020-01-22T13:50:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [January 22, 2020, 1:53pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/6 "2020-01-22T13:53:29Z")

</div>

> `CMakeFiles\3.16-rc3\CompilerIdFortran`

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

> ```auto
> -- 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 `*`?

---

<div class="post-metadata">

### Author: ![MartinBeseda](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@MartinBeseda](https://discourse.cmake.org/u/MartinBeseda)
#### Post date: [January 23, 2020, 1:31pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/7 "2020-01-23T13:31:45Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![imikejackson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imikejackson/32/301_2.png) [@imikejackson](https://discourse.cmake.org/u/imikejackson)
#### Post date: [January 27, 2020, 3:26pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/8 "2020-01-27T15:26:19Z")

</div>

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](https://my.cdash.org/buildSummary.php?buildid=1765288)

---

<div class="post-metadata">

### Author: ![rjk9w5](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rjk9w5](https://discourse.cmake.org/u/rjk9w5)
#### Post date: [May 28, 2020, 4:53pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/9 "2020-05-28T16:53:17Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 29, 2020, 10:53am UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/10 "2020-05-29T10:53:17Z")

</div>

> 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.

---

<div class="post-metadata">

### Author: ![rjk9w5](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rjk9w5](https://discourse.cmake.org/u/rjk9w5)
#### Post date: [May 29, 2020, 2:40pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/11 "2020-05-29T14:40:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![markultraleap](https://discourse.cmake.org/user_avatar/discourse.cmake.org/markultraleap/32/2414_2.png) [@markultraleap](https://discourse.cmake.org/u/markultraleap)
#### Post date: [May 10, 2022, 6:01pm UTC](https://discourse.cmake.org/t/how-to-set-up-compilation-with-intel-fortran-compiler-on-windows-correctly/532/12 "2022-05-10T18:01:13Z")

</div>

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.
