Sublime Text 2 Build (Ctrl +B) Intel Fortran Compiler

Sublime Text 3 intel oneAPI Fortran build system

I found the answer. Explanation below. Posting the working build system here for visibility.

This should be the build system:

{
"cmd": ["cmd", "/e:on", "/v:on", "/S", "/k", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\Intel\\oneAPI\\compiler\\latest\\windows\\bin\\intel64;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/s", "/c", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file} && ${file_base_name}"]
}
]
}

Why the problem happens

For starters, ipsxe-comp-vars is a batch file which when run, sets up environment variables required to execute the intel compilers. This file is specific to Intel Parallel Studio XE (IPSXE). Now, when installing IPSXE, it would add this batch file to your PATH, meaning you could simply call ipsxe-comp-vars from any directory to set up the required environment variables.

Intel oneAPI has a differently named file, that essentially does the same thing, called setvars.bat. This file is stored in:

C:\Program Files (x86)\Intel\oneAPI\setvars.bat

So, at first it seems that calling ipsxe-comp-vars fails because the file is named differently. However, unlike IPSXE did with ipsxe-comp-vars, oneAPI does not add setvars to PATH, so you cannot simply call setvars, you have to usethe full path.

How to solve it

With IPSXE, you could call ipsxe-comp-vars and it would run the batch file that sets up environment variables, but with oneAPI either you add the file to PATH (not reccomended because it has a generic name), or you use the full path when calling it (same as above):

C:\Program Files (x86)\Intel\oneAPI\setvars.bat

Now, because you have to plug this in into the build system config, you need to format it correctly. ST runs the commands in a cmd.exe, so you have to use the correct options and format the path in a way that cmd can understand it:
options (you can get a full list by opening a cmd prompt, typing cmd /? and hitting return):

 - /e:on    Enables command extensions
- /v:on Enables extension of environment variables
- /s Modifies how the string following a /c or /k is read
- /k Executes the string command and continues

The path to the setvars.bat file must be formatted as follows:

C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat
  • Each \ separating dirs needs to be escaped (using \ as well)
  • needs to be enclosed in double quotes, since it contains a whitespace. Each double quote needs to escaped as well (once again with )

The following options are specific to the setvars.bat file:

- intel64      specifies 64-bit configuration
- vs2022 specifies Visual Studio 2022 as the developer cmd or
powershell version to use

Finally, ifort is called on the current file with ifort ${file}

Additionally, the build system is completed with a variant "Run". This variant runs the output file once it has been compiled(&& ${file_base_name}), and will show the output in the Sublime Text 3 console (does not accept inputs, if anyone knows how to setup up sublimeREPL for Fortran please tell me)

Sublime Text: compiler build options

Create a new file with the following contents:

{
"cmd": ["g++", "${file}", "-o", "${file_base_name}", "-lboost_filesystem"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c++",
"shell": true
}

and save it as Packages/User/C++_Boost.sublime-build where Packages is the folder opened when you select Preferences -> Browse Packages.... Next, select Tools -> Build System -> C++_Boost and you should be able to build by hitting CtrlB.



Related Topics



Leave a reply



Submit