How to use ifort (+ fpm) on Windows?

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 project. Unfortunately, it compiles the src files, but fails to build the executables, producing the following output:

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:

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.

1 Like

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

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

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.

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! :slight_smile:


The 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 ↩︎

3 Likes

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

# 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

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.

Or just:

>> 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 ::
1 Like