# How to use ifort (+ fpm) on Windows?

**URL:** <https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540>\
**Category:** fpm\
**Created:** [October 15, 2022, 8:38pm UTC](https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540 "2022-10-15T20:38:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HugoMVale](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@HugoMVale](https://fortran-lang.discourse.group/u/HugoMVale)\
**Post date:** [October 15, 2022, 8:38pm UTC](https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540/1 "2022-10-15T20:38:57Z")

</div>

Until now, I have been using gfortran + fpm + VS Code.  
Today, I decided to give **ifort** a try. I downloaded the oneAPI “colossus” (OMG, so many Gb…). I did a smoke test inside VS Community, and it worked. Afterwards, I added `ifort.exe` to path.

Then, tried to use **fpm+ifort** with [this](https://github.com/HugoMVale/HR-WENO) project. Unfortunately, it compiles the src files, but fails to build the executables, producing the following output:

```auto
PS C:\Code\hrweno> fpm build --compiler ifort          
hrweno_kinds.F90 done.
stdlib_kinds.f90 done.
hrweno.f90 done.
stdlib_optval.f90 done.
stdlib_ascii.f90 done.
fluxes.f90 done.
tvdode.f90 done.
grid.f90 done.
stdlib_string_type.f90 done.
stdlib_strings.f90 done.
example1_burgers_1d_fv.f90 done.
stdlib_string_type_constructor.f90 done.
stdlib_strings_to_string.f90 done.
example2_pbe_2d_fv.f90 done.
libhrweno.a done.
example1_burgers_1d_fv.exe compiling...
example2_pbe_2d_fv.exe compiling...
[88%]Compiling...Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained

Error termination. Backtrace:

Could not print backtrace: libbacktrace could not find executable to open
#0 0x4d809aca
#1 0x4d7905f1
#2 0x4d74f91d
#3 0x4d820ef9
#4 0x4d6ab5cd
#5 0xd6b65bb4
#6 0xd6b5ff71
#7 0xd6b4c23b
#8 0xd6b4c340
#9 0x9f44fcb7
#10 0xb8ab4b4a
#11 0xc9f4dfb3
#12 0xc9f4e08b
#13 0xc99554df
#14 0xcac6485a
#15 0xffffffff

```

If I try running the tests, it complains about preprocessor directives:

```auto
PS C:\Code\hrweno> fpm test --compiler ifort        
testdrive.F90 failed.
[10%]Compiling...
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.6.0 Build 20220226_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

build\dependencies\test-drive\src\testdrive.F90(15): warning #5117: Bad # preprocessor line
#ifndef WITH_QP
-^
build\dependencies\test-drive\src\testdrive.F90(16): warning #5117: Bad # preprocessor line
#define WITH_QP 0
-^
build\dependencies\test-drive\src\testdrive.F90(17): warning #5117: Bad # preprocessor line
#endif
...

```

Since the equivalent commands run perfectly well with gfortran, I conclude I am doing a silly mistake somewhere. Maybe forgetting some flag(s)? Maybe some environment variables?  
Any hint is very much appreciated.

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [October 15, 2022, 11:36pm UTC](https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540/2 "2022-10-15T23:36:15Z")

</div>

Just a guess, but perhaps the case of the file extension does not automatically trigger preprocessing with ifort on Windows? You might try adding `--flag '-cpp'` (i.e. `fpm test --compiler ifort --flag '-cpp'`).

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [October 16, 2022, 12:08am UTC](https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540/3 "2022-10-16T00:08:37Z")

</div>

That’s correct. Ifort has to be told to preprocess on windows. It’s either -fpp or -cpp (I can’t remember).

---

<div class="post-metadata">

**Author:** ![lkedward](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lkedward/32/72_2.png) [@lkedward](https://fortran-lang.discourse.group/u/lkedward)\
**Post date:** [October 16, 2022, 9:05am UTC](https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540/4 "2022-10-16T09:05:52Z")

</div>

> [@HugoMVale](#):
>
> Afterwards, I added `ifort.exe` to path.

I believe this is your problem: adding `ifort.exe` to your path is not sufficient to initialise the Intel compiler environment. The Intel suite must be initialised at the command line using the `setvars.bat`\[1\] batch script provided.

_e.g._

```auto
c:\tmp>call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"

```

With a correctly initialised environment, I am able to compile your project and run the tests with no problem (though one of the tests fails).

Hope that helps! 🙂

* * *

The [quickstart-fortran](https://github.com/LKedward/quickstart-fortran) environment provides the `intel-setvars` helper command to simplify the initialisation of the Intel suite.

* * *

1. Normally found in `C:\Program Files (x86)\Intel\oneAPI`

---

<div class="post-metadata">

**Author:** ![HugoMVale](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@HugoMVale](https://fortran-lang.discourse.group/u/HugoMVale)\
**Post date:** [October 16, 2022, 10:15pm UTC](https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540/5 "2022-10-16T22:15:33Z")

</div>

Thanks. After posting the question, I kept searching for solutions and found that oneAPI has a VS Code extension [Environment Configurator for Intel® oneAPI Toolkits - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=intel-corporation.oneapi-environment-configurator) that takes care of setting the environment variables. Unfortunately, the problem remains.  
I also tried `quickstart-fortran`, but the result is the same, as shown below for fpm’s hello world example:

```auto
# Quickstart Fortran Command Line
# Path variable initialised
...
C:\Code\test_ifort>fpm clean
Delete build, excluding dependencies (y/n)? y
 + rmdir /s/q build\ifort_782887A201FCE169

C:\Code\test_ifort>fpm run --compiler ifort --verbose
 <INFO> BUILD_NAME: build\ifort
 <INFO> COMPILER: ifort
 <INFO> C COMPILER: icc
 <INFO> COMPILER OPTIONS: /warn:all /check:all /error-limit:1 /Od /Z7 /assume:byterecl /traceback
 <INFO> C COMPILER OPTIONS:
 <INFO> LINKER OPTIONS:
 <INFO> INCLUDE DIRECTORIES: []
 [0%] test_ifort.exe
 + ifort /warn:all /check:all /error-limit:1 /Od /Z7 /assume:byterecl /traceback build\ifort_782887A201FCE169\test_ifort\app_main.f90.o build\ifort_782887A201FCE169\test_ifort\libtest_ifort.a -o build\ifort_782887A201FCE169\app\test_ifort.exe
Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained

Error termination. Backtrace:

Could not print backtrace: libbacktrace could not find executable to open
#0 0x4d78e81b
#1 0x4d785144
#2 0x4d78049d
#3 0x4d794d9c
#4 0x4d77f00e
#5 0x4d67147c
#6 0x4d66b501
#7 0x4d645b6a
#8 0x4d645e6d
#9 0x4d7426d8
#10 0x4d64858b
#11 0x4d63c7ac
#12 0x4d632254
#13 0x4d7a6f43
#14 0x4d631444
#15 0x4d631145
#16 0xc99554df
#17 0xcac6485a
#18 0xffffffff

C:\Code\test_ifort>fpm clean
Delete build, excluding dependencies (y/n)? y
 + rmdir /s/q build\ifort_782887A201FCE169

C:\Code\test_ifort>fpm run
test_ifort.f90 done.
main.f90 done.
libtest_ifort.a done.
test_ifort.exe done.
[100%] Project compiled successfully.
 Hello, test_ifort!

C:\Code\test_ifort>

```

Computers can be quite frustrating sometimes… Maybe something is missing in path. I’m clueless.

![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/5/5e3328fbc2463bb529d1476a120d6f750731e22a.png)

---

<div class="post-metadata">

**Author:** ![zoziha](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zoziha/32/582_2.png) [@zoziha](https://fortran-lang.discourse.group/u/zoziha)\
**Post date:** [October 17, 2022, 1:29am UTC](https://fortran-lang.discourse.group/t/how-to-use-ifort-fpm-on-windows/4540/6 "2022-10-17T01:29:09Z")

</div>

It appears that ifort’s linker was not introduced into the environment variables, causing errors to link the final executable.

From my experience, I don’t recommend setting oneAPI environment variables **manually** , it’s too difficult. As an environment, oneAPI contains many components. I suggest you try the `Intel oneAPI command prompt for Intel 64 for Visual Studio 2019` in **the Windows start menu** to start the oneAPI environment, refer to [here](https://github.com/fortran-lang/fpm/discussions/717#discussioncomment-3091462).

Or just:

```nohighlight
>> cmd /E:ON /K "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 vs2019
:: initializing oneAPI environment...
   Initializing Visual Studio command-line environment...
   Visual Studio version 16.11.19 environment configured.
   "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\"
   Visual Studio command-line environment initialized for: 'x64'
: compiler -- latest
: debugger -- latest
: dev-utilities -- latest
: dpcpp-ct -- latest
: dpl -- latest
: inspector -- latest
: mpi -- latest
: tbb -- latest
: vtune -- latest
:: oneAPI environment initialized ::

```
