Programming Guide

Contents

Automate the setvars.bat Script with Microsoft Visual Studio*

The
setvars.bat
script sets up the environment variables needed to use the oneAPI toolkits. This script must be run every time a new terminal window is opened for command-line development. The
setvars.bat
script can also be run automatically when Microsoft Visual Studio is started. You can configure this feature to instruct the
setvars.bat
script to set up a specific set of oneAPI tools by using the
SETVARS_CONFIG
environment variable.

SETVARS_CONFIG Environment Variable States

The SETVARS_CONFIG environment variable enables automatic configuration of the oneAPI development environment when you start your instance of Microsoft Visual Studio. The variable has three conditions or states:
  • Undefined (the
    SETVARS_CONFIG
    environment variable does not exist)
  • Defined but empty (the value contains nothing or only whitespace)
  • Defined and points to a
    setvars.bat
    configuration file
If
SETVARS_CONFIG
is undefined there will be no attempt to automatically run
setvars.bat
when Visual Studio is started. This is the default case, since the
SETVARS_CONFIG
variable is not defined by the oneAPI installer.
If
SETVARS_CONFIG
is defined and has no value (or contains only whitespace), the
setvars.bat
script will be automatically run when Visual Studio is started. In this case, the
setvars.bat
script initializes the environment for
all
oneAPI tools that are installed on your system. For more information about running the
setvars.bat
script, see Build and Run a Sample Project Using the Visual Studio* Command Line.
When
SETVARS_CONFIG
is defined with the absolute pathname to a
setvars
configuration file, the
setvars.bat
script will be automatically run when Visual Studio is started. In this case, the
setvars.bat
script initializes the environment for only those oneAPI tools that are defined in the
setvars
configuration file. For more information about how to create a setvars config file, see Using a Config File with setvars.bat.

Create a setvars Configuration File

Create a new text file that you will use as your
setvars
configuration file. In this example, the file is named
config.txt
and is located in the
C:\Program Files (x86)\Intel\oneAPI
folder.
A
setvars
configuration file can have any name and can be saved to any location on your hard disk, as long as that location and the file are accessible and readable by Visual Studio. (A plug-in that was added to Visual Studio when you installed the oneAPI tools on your Windows system performs the SETVARS_CONFIG actions; that is why Visual Studio must have access to the location and contents of the
setvars
configuration file.)
If you leave the
setvars
config file empty, the
setvars.bat
script will initialize your environment for
all
oneAPI tools that are installed on your system. This is equivalent to defining the
SETVARS_CONFIG
variable with an empty string. See Using a Config File with setvars.bat for details regarding what to put inside of your setvars config file.

Define the SETVARS_CONFIG Environment Variable

  1. Press the Windows key on your keyboard, and then press the letter 's' to open the search window.
  2. Enter
    variable
    in the search window.
  3. Select
    Edit the System Environment Variables
    .
    screen shot
  4. Click the
    Environment Variables
    button.
    screen shot
  5. From the
    User Variables
    list, select
    SETVARS_CONFIG
    . Then click
    Edit
    .
    If
    SETVARS_CONFIG
    does not appear in your
    User Variables
    list, click
    New
    .
  6. In the
    Variable Name
    field, enter
    SETVARS_CONFIG
    .
  7. Click
    Browse File
    . Locate and click on the text file that you created.
  8. Click
    Open
    .
  9. Click
    OK
    to close the
    User Variable
    window.
  10. Click
    OK
    to close the
    Environment Variables
    window.
  11. Click
    OK
    to close the
    System Properties
    window.

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.