Get Started on Linux*
Before You Begin
Set Environment Variables for CLI Development
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 Directory Layout, including how to initialize the environment and advantages with the Unified Directory Layout, refer to Use the setvars and oneapi-vars Scripts with Linux.
Before using the compiler from a Command Line Interface (CLI), you must first configure the compiler environment variables. You can set up environment variables by running a script named setvars in the Component Directory Layout or oneapi-vars in the Unified Directory Layout. By default, changes to your environment that the setvars.sh or oneapi-vars.sh script sources apply only to the terminal session where you sourced the environment script. For each new terminal session, you must source the script again.
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 Environment Modulefiles with Linux.
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:
- To use an Intel GPU, install the latest Intel GPU drivers.
- To use an AMD GPU (Linux only):
- install the oneAPI for AMD GPUs plugin from Codeplay.
- Download oneAPI for AMD GPUs.
- To use an NVIDIA GPU (Linux and Windows):
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
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.
- Start Eclipse
- Select Help > Install New Software
- Select Add to open the Add Site dialog
- 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
- Select the options beginning with Intel, select Next, then follow the installation instructions
- When asked if you want to restart Eclipse*, select Yes
Build a new project or open an existing project.
- Open Existing Project or Create New Project on Eclipse
- Right click on Project > Properties > C/C++ Build > Tool chain Editor
- Select Intel DPC++/C++ Compiler from the right panel
Set build configurations.
- Open Existing Project on Eclipse
- Right click on Project > Properties > C/C++ Build > Settings
- 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.
- 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; }
- Open a terminal window.
- 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 Use the setvars and oneapi-vars Scripts with Linux - 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. - 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:
- Compile hello-world.cpp:
icpx hello-world.cpp -c
The -c option prevents linking at this step. - 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.