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

ID 767258
Date 6/24/2024
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 for CLI Development

NOTE:

The Unified Directory Layout was implemented in 2024.0. If you have multiple toolkit versions installed, the Unified layout ensures that your development environment contains the correct component versions for each installed version of the toolkit.

The directory layout used before 2024.0, the Component Directory Layout, is still supported on new and existing installations.

For detailed information about the Unified layout, including how to initialize the environment and advantages with the Unified layout, refer to Use the setvars and oneapi-vars Scripts with Linux.

Compiler environment variables must first be configured if using the compiler from a Command Line Interface (CLI). Environment variables are set up with a script called setvars in the Component Directory Layout or oneapi-vars in the Unified Directory Layout. By default, changes to your environment made by sourcing the setvars.sh or oneapi-vars.sh script apply only to the terminal session in which the environment script was sourced. You must source the script for each new terminal session.

Detailed instructions on using the setvars.sh or oneapi-vars.sh script are found in Use the setvars and oneapi-vars Scripts with Linux.

Optionally use one-time setup for setvars.sh as described in Use Modulefiles with Linux*.

GPU Drivers or Plug-ins (Optional)

You can develop oneAPI applications using C++ and SYCL* that 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:

Invoke the Compiler from the Command Line

The Intel® oneAPI DPC++/C++ Compiler provides multiple drivers that can be used to invoke the compiler from the command line. Use the driver appropriate for your specific project.

Language Compiler Driver for Linux Compiler Driver for Windows Option Style Notes

C

icx

icx-cc

icx-cc

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

Clang-style

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

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

C/C++

icx-cl (see notes)

icx

icx-cl

MSVC-style

icx is the recommended default driver for Windows.

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

NOTE:
On Linux, icx-cl is experimental and requires the Microsoft Visual Studio Package.

Invoke the compiler on the command line 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 AMD or NVIDIA GPU, refer to the corresponding Codeplay plugin get started guide for detailed compilation instructions:

Invoke the Compiler From 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

Example: 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. Open a terminal window.
  3. If you are not using one-time setup for setvars.sh, set environment variables by sourcing setvars:

    Component Directory Layout

    source <install-dir>/setvars.sh

    Unified Directory Layout

    source <install-dir>/<toolkit-version>/oneapi-vars.sh
    For information about the <install-dir> location for Component or Unified layout on system-wide or private installations, refer to Using the setvars and oneapi-vars Scripts with Linux*.
  4. From the terminal window, issue the following command to compile hello-world.cpp:
    icpx hello-world.cpp -o hello-world
    The -o option specifies the file name for the generated output.
  5. 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.

© Codeplay Software Limited. Intel, the Intel logo, Codeplay, Codeplay logo and other Intel marks are trademarks of Intel Corporation or its subsidiaries. Other names and brands may be claimed as the property of others.