Get Started with the Intel® oneAPI DPC++/C++ Compiler

ID 767258
Date 12/16/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Get Started on Linux*

Before You Begin

Set Environment Variables

Before you can use the compiler, you must first set the environment variables by sourcing the environment script using the initialization utility. This initializes all the tools in one step.

  1. Determine your installation directory,<install_dir>:
    1. If your compiler was installed in the default location by a root user or sudo user, the compiler will be installed under/opt/intel/oneapi. In this case, <install_dir> is /opt/intel/oneapi.
    2. For non-root users, your home directory under intel/oneapi is used. In this case, <install_dir> will be $HOME/intel/oneapi.
    3. For cluster or enterprise users, your admin team may have installed the compilers on a shared network file system. Check with your local admin staff for the location of installation (<install_dir>).
  2. Source the environment-setting script for your shell:
    1. bash: source <install_dir>/setvars.sh intel64
    2. csh/tcsh: source <install_dir>/setvars.csh intel64
Install GPU Drivers or Plug-ins (Optional)

You can develop oneAPI applications using C++ and SYCL* that will run on Intel, AMD*, or NVIDIA* GPUs.

To develop and run applications for specific GPUs you must first install the corresponding drivers or plug-ins:

Option 1: Use the Command Line

The Intel® oneAPI DPC++/C++ Compiler provides multiple drivers:

Language Linux Drivers Windows Drivers Option Style Notes

C

icx

icx-cc

icx-cc

Linux-style

icx is the recommended default C driver for Linux.

If you use icx with a C++ source file, it is compiled as a C++ file. Use icx to link C object files.

icx-cc is the Microsoft-compatible variant of icx.

C++

icpx

icpx

Linux-style

icpx is the recommended default C++ driver for Linux.

If you use icpx with a C source file, it is compiled as an C++ file. Use icpx to link C++ object files.

C/C++

icx-cl

icx

icx-cl

Windows-style

icx is the recommended default driver for Windows.

icx-cl is the Microsoft-compatible variant of icx. On Linux, icx-cl requires the Microsoft Visual Studio package.

Invoke the compiler using the following syntax:

{compiler driver} [option] file1 [file2...]

For example:

icpx hello-world.cpp

For SYCL compilation, use the -fsycl option with the C++ driver:

icpx -fsycl hello-world.cpp

NOTE:
When using -fsycl, -fsycl-targets=spir64 is assumed unless the -fsycl-targets is explicitly set in the command.

If you are targeting an NVIDIA or AMD GPU, refer to the corresponding GPU plugin get started guide for detailed compilation instructions:

Option 2: Use the Eclipse* CDT

Follow these steps to invoke the compiler from within the Eclipse* CDT.

Install the Intel® Compiler Eclipse CDT plugin.

  1. Start Eclipse
  2. Select Help > Install New Software
  3. Select Add to open the Add Site dialog
  4. Select Archive, browse to the directory <install_dir>/compiler/<version>/linux/ide_support, select the .zip file that starts with com.intel.dpcpp.compiler, then select OK
  5. Select the options beginning with Intel, select Next, then follow the installation instructions
  6. When asked if you want to restart Eclipse*, select Yes

Build a new project or open an existing project.

  1. Open Existing Project or Create New Project on Eclipse
  2. Right click on Project > Properties > C/C++ Build > Tool chain Editor
  3. Select Intel DPC++/C++ Compiler from the right panel

Set build configurations.

  1. Open Existing Project on Eclipse
  2. Right click on Project > Properties > C/C++ Build > Settings
  3. Create or manage build configurations in the right panel

Build a Program From the Command Line

Use the following steps to test your compiler installation and build a program.

  1. Use a text editor to create a file called hello-world.cpp with the following contents:
    #include <iostream>
    
    int main()
    {
        std::cout << “Hello, world!\n”;
    
        return 0;
    }
    			
  2. Compile hello-world.cpp:
    icpx hello-world.cpp -o hello-world
    The -o option specifies the file name for the generated output.
  3. Now you have an executable called hello-world which can be run and will give immediate feedback:
    hello-world
    Which outputs:
    Hello, world!

You can direct and control compilation with compiler options. For example, you can create the object file and output the final binary in two steps:

  1. Compile hello-world.cpp:
    icpx hello-world.cpp -c
    The -c option prevents linking at this step.
  2. Use the icpx compiler to link the resulting application object code and output an executable:
    icpx hello-world.o -o hello-world
    The -o option specifies the generated executable file name.

Refer to Compiler Options for details about available options.