# How to use intel compiler with fpm?

**URL:** <https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406>\
**Category:** fpm\
**Created:** [July 29, 2024, 12:50am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406 "2024-07-29T00:50:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [July 29, 2024, 12:50am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/1 "2024-07-29T00:50:12Z")

</div>

I have found some previous discussions on this

[Is it possible to specify the compiler in the fpm.toml? - Help / fpm - Fortran Discourse (fortran-lang.discourse.group)](https://fortran-lang.discourse.group/t/is-it-possible-to-specify-the-compiler-in-the-fpm-toml/4927/8)

I still do not understand the steps to use fpm with intel. I want to use it for windows 10. What I mean is perhaps where I should replace gfortran with ifx or whatever I need to modify. I do not see any relevant info here [How-To guides — Fortran Package Manager (fortran-lang.org)](https://fpm.fortran-lang.org/how-to/index.html)

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [July 29, 2024, 8:21am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/2 "2024-07-29T08:21:50Z")

</div>

It should be as simple as,

```txt
fpm build --compiler ifx

```

* * *

Alternatively, you can set an environment variable in your session:

```auto
set FPM_FC=ifx

```

More details on the set command here: [set | Microsoft Learn](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/set_1)

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [July 29, 2024, 9:18am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/3 "2024-07-29T09:18:32Z")

</div>

Yes. Note all the environment variables and command keywords related to compiling and linking options are described in the built-in help text, so “fpm help build” provides some descriptions.

All the help text can be placed in a text file with a single command

```plaintext
fpm manual >fpm.txt

```

which describes using a response file as well.

For example, in the same directory as the fpm.toml manifest file create a file called “fpm.rsp” with lines like

```plaintext
@buildi
options build --compiler ifx --verbose 
@buildg
options build --compiler gfortran --verbose

```

and then you can use the abbreviations you just created by using the names on the command lines:

```plaintext
fpm @buildi

```

as well. This is most useful when you want to repeatedly use long custom compiler and loader options.

Of course, you can also use wrapper scripts and shell aliases, but that varies from system to system type.

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 29, 2024, 10:34am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/4 "2024-07-29T10:34:37Z")

</div>

Using ifx on windows requires properly settings a lot of paths and environmental variables.  
The simplest is usually to use the intel console shipped with the compiler. It’s the classical cmd in which the required variables are properly set.

Then, you can just proceed as @ivanpribec said. And if you are using response file as @urbanjost suggested, just do not do it from a powershell terminal (@ character is not properly interpreted)

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [July 29, 2024, 3:16pm UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/5 "2024-07-29T15:16:14Z")

</div>

@ in powershell is a problem, but double-quoting or using names with a dash in them works around it, as per

> <https://github.com/urbanjost/M_CLI2/issues/19>
>
> I was experimenting response file for fpm and running command like \`fpm @build\` …from a powershell terminal on Windows. 
> The issue is that \`@\` has a special meaning in powershell and the command cannot be interpreted. It only returns the help for fpm 
> \`\`\`cmd
> Fortran Package Manager:
>  
> USAGE: fpm \[SUBCOMMAND \[SUBCOMMAND\_OPTIONS\] \]|\[--list|--help|--version\]
> where SUBCOMMAND is commonly new|build|run|test
> 
> subcommand may be one of
> 
> build Compile the package placing results in the "build" directory
> help Display help
> list Display this list of subcommand descriptions
> new Create a new Fortran package directory with sample files    
> run Run the local package application programs
> test Run the test programs
> update Update and manage project dependencies
> ...
> \`\`\`
> 
> \## Workaround
> sections in the rsp containing hyphens are perfectly fine, so I can run \`fpm @gfortran-build\`.
> Or, I can also use the classical cmd prompt.
> 
> There is probably not much to do here, but I thought I report the issue for the record in case someone faces the same problem.

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [July 30, 2024, 8:04am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/6 "2024-07-30T08:04:56Z")

</div>

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

i did change from system variables and created this new one

![fpm_environment](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/8/8c59a922c01d797057f85001b719b3090fd51bbc.png)

The fpm build manual says

> ENVIRONMENT VARIABLES  
> FPM\_FC sets the path to the Fortran compiler used for the build,  
> will be overwritten by --compiler command line option

So the environment variable here is supposed to find the location of intel compiler by itself ?

---

<div class="post-metadata">

**Author:** ![Tavi007](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@Tavi007](https://fortran-lang.discourse.group/u/Tavi007)\
**Post date:** [July 30, 2024, 9:06am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/7 "2024-07-30T09:06:59Z")

</div>

You haven’t set all the environment varaibles that are needed for the compiler to work.

If you are using the Intel oneApi toolkit, you should find a .bat file, that will set up everything for you. You should find it here:  
C:\Program Files (x86)\Intel\oneAPI\setvars.bat

So run it in the terminal, then you should be able to find the ifort command (the ifx compiler should be available for you now too)

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 30, 2024, 9:19am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/8 "2024-07-30T09:19:01Z")

</div>

If you do not use the oneApi command prompt (that simply run the setvars mentioned above) that will be a lot trickier. In addition, since you are using the msys2 terminal, the variables need to be set in your mingw environment, not on windows.

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [July 30, 2024, 10:11am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/9 "2024-07-30T10:11:43Z")

</div>

so far my understanding is:

There are three terminals

1. default intel terminal which I usually use to run the code with intel compiler (It comes with intel).
2. windows terminal.
3. Msys2 terminal for fmp.

So now the relevant options are 1) and 3).

Now I wanna know which command I should use for setting environment variable in the Msys2 terminal? and how about the path? path is the same as environment variable? I think they are different!

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 30, 2024, 10:32am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/10 "2024-07-30T10:32:39Z")

</div>

From my personal experience, only option 1 is straightforward and with option 3 you will face many issues starting with incompatible paths between Windows and the Unix kinds used by [msys2](https://www.msys2.org/docs/filesystem-paths/).  
The simplest for you is to use option 1 and make sure that fpm is in the Windows Path. If you installed fpm with msys2, just add the installation folder into your path environmental variables. On my computer, fpm is installed under “C:\msys64\mingw64\bin”. Once done, just start the intel terminal and type `fpm --help` to make sure it is accessible.  
From there, you should be good to go.

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 30, 2024, 11:32am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/11 "2024-07-30T11:32:45Z")

</div>

By the way, if you are using VSCode you can add the intel terminal to your default terminals.  
Simply create a script named `intel.cmd` with the following command

```cmd
%ComSpec% /E:ON /K ""C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 vs2019"

```

just make sure that the paths and arguments are correct for you. I usually place that file in the .vscode folder.  
Then, in your \*.code-workspace (alternatively, in the settings.json), paste the following

```json
"settings" : {
...
      "terminal.integrated.profiles.windows": {
            "Intel Prompt": {
                "path": [
                    "${env:windir}\\System32\\cmd.exe"
                ],
                "args": ["/K",
                         ".\\.vscode\\intel.cmd"],
                "icon": "terminal-cmd"
            }
        },
        "terminal.integrated.defaultProfile.windows": "Intel Prompt"
}

```

This will run the script `setvars.bat` every time you start a new terminal

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 30, 2024, 4:39pm UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/12 "2024-07-30T16:39:37Z")

</div>

@davidpfister what if Windows had a shell that would be a strict subset of Bash/Zsh, but unlike git-bash/msys2 without any weird/confusing Linux like path overlay, so it would handle Windows paths directly? I would think a lot of the native Windows command-line programs might work better, and as a bonus one could write exactly the same script to build a project (or do other things) and it would run unmodified on Linux, macOS and Windows, which would be very handy for end users and at a CI, etc.

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 30, 2024, 5:22pm UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/13 "2024-07-30T17:22:48Z")

</div>

It would sound like Christmas to me 🎅. You also have to consider that the rules for specifying the root is different, the max path length is different… and allowed characters and spaces. In the example mentioned above with vscode I could not get it to work without using a script because of the space between ‘Program’ and ‘Files’ and because vscode does not support double quoting the arguments.

From what I saw Cygwin is shipped with some utility program (cygpath) that can do the path conversion.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [July 30, 2024, 5:46pm UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/14 "2024-07-30T17:46:52Z")

</div>

@davidpfister excellent. 🙂 I have not fully figured out all cases yet, but I’ve noticed PowerShell just automatically quotes Windows paths with spaces. So that’s how the interactive Bash like shell can behave too. Instead of:

```auto
%ComSpec% /E:ON /K ""C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 vs2019"

```

The Bash like script would be something like:

```bash
$ComSpec /E:ON /K '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 vs2019'

```

It needs to work with most `.bat` files, I am hoping that if one can check what environment variables changed, the Bash-like shell can figure it out and bring it to the current environment.

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 30, 2024, 7:49pm UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/15 "2024-07-30T19:49:24Z")

</div>

If that helps, upon installation, oneapi installer creates the env. var. ONEAPI\_ROOT that should correspond to “C:\Program Files (x86)\Intel\oneAPI”. It still needs to be double-quoted though.

As for powershell, despite the disturbing syntax, it’s a pretty cool shell. Too bad it does not handle response files very well as mentionned above.

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [July 31, 2024, 6:34am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/16 "2024-07-31T06:34:05Z")

</div>

> [@davidpfister](#):
>
> The simplest for you is to use option 1

 ![intel_setting](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/1/18f266ecded84034ec42af986d32f411d54b2b49.png)

> [@davidpfister](#):
>
> fpm is in the Windows Path

I set the variable there in the intel batch file.

> [@davidpfister](#):
>
> If you installed fpm with msys2, just add the installation folder into your path environmental variables. On my computer, fpm is installed under “C:\msys64\mingw64\bin”

Where should I add this and how? If this is for msys2, I do not know the msys2 settings for path variables!

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 31, 2024, 6:49am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/17 "2024-07-31T06:49:46Z")

</div>

Sorry if I was not clear. I assumed that you used msys2 to install fpm and because of this, fpm will not be automatically present in the Windows path.  
So you can proceed as follows:

- install `fpm` with your method of [choice](https://fpm.fortran-lang.org/install/index.html)
- check the installation folder of `fpm`:  
- if you used msys2, the path should be “C:\msys64\mingw64\bin”  
- if you used winget, the path should be %LOCALAPPDATA%\Microsoft\WinGet\Packages  
- if you build fpm from source, then if could be whatever
- if not present already, [add the folder path to your environmental variables](https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14)):
- open the intel terminal
- ‘cd’ to your source code folder (where the fpm.toml file is located)
- run `fpm build --compiler ifx`

(since you are using a script you can simply add the line `fpm build` after the call to `set FPM_FC ifx`)

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [July 31, 2024, 7:47am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/18 "2024-07-31T07:47:37Z")

</div>

> [@davidpfister](#):
>
> if you used msys2, the path should be “C:\msys64\mingw64\bin”

 ![fpm_location](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/1/16266cd00eefd8d689cca14a08e050c57b35a1af.png)

> [@davidpfister](#):
>
> (since you are using a script you can simply add the line `fpm build` after the call to `set FPM_FC ifx`)

 ![fpm_build_intel](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/4/4144f3199a53f7ac40153bae5626d3e3f06df053.png)

> C:\Program Files (x86)\Intel\oneAPI\>cd /d C:\Users\owner\Desktop\fpm\_test  
> C:\Users\owner\Desktop\fpm\_test\>fpm build --compiler ifx  
> ‘fpm’ is not recognized as an internal or external command,  
> operable program or batch file.

---

<div class="post-metadata">

**Author:** ![davidpfister](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/davidpfister/32/3949_2.png) [@davidpfister](https://fortran-lang.discourse.group/u/davidpfister)\
**Post date:** [July 31, 2024, 8:17am UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/19 "2024-07-31T08:17:38Z")

</div>

The last message confirm that the path to `fpm` is not set in you PATH env. var.  
Try this in your script (at the very beginning)

```cmd
set PATH=%PATH%;“C:\msys64\mingw64\bin”

```

that should do the trick

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [July 31, 2024, 2:11pm UTC](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406/20 "2024-07-31T14:11:08Z")

</div>

After revisiting this (not an MSWindows/powershell user so not positive) but it looks like @ is only special at the beginning of a simple name so allowing an @ at the end to be treated as equivalent to an @ at the beginning of the word seems more appealing than double-quoting or creating responses with a dash in the name. I am not sure how much interest in that there is but I can put in a PR for that if it seems like a solution anyone would use/need.

[Next page](https://fortran-lang.discourse.group/t/how-to-use-intel-compiler-with-fpm/8406.md?page=2)
