How to Link Your C++ Applications with Intel® DAAL?

Intel® Data Analytics Acceleration Library (Intel® DAAL) provides pre-built binary libraries ready to be linked into C++ applications. Linking is supported by all C++ compilers. This article shows linking examples using the Intel C/C++ compiler and GCC. For information on how to use Intel DAAL with Microsoft Visual Studio, refer to the online article Getting Started with Intel Data Analytics Acceleration Library for Windows

We assume the following environment variables are defined:

DAALROOT=<installation location of DAAL>
DAALINCLUDE=$DAALROOT/include

For Intel64 architectures
DAALLIB=$DAALROOT/lib/intel64
For IA-32 architectures
DAALLIB=$DAALROOT/lib/ia32

Linking with Intel C/C++ Compiler

Dynamic linking

The easiest way of linking is to use the -daal (Linux and OS X) or the /Qdaal (Windows) switch. This by default tells the compiler to use threaded (parallel) DAAL, which is equivalent to -daal=parallel (Linux and OS X) or /Qdaal=parallel (Windows). To specify using the sequential (single-threaded) DAAL, use -daal=sequential (Linux and OS X) or /Qdaal=sequential (Windows). For example,

  • On Linux or OS X

    icc -I$DAALINCLUDE daal_test.cpp -daal 
    icc -I$DAALINCLUDE daal_test.cpp -daal=parallel
    icc -I$DAALINCLUDE daal_test.cpp -daal=sequential
  • On Windows

    icc /I%DAALINCLUDE% daal_test.cpp /Qdaal
    icc /I%DAALINCLUDE% daal_test.cpp /Qdaal=parallel
    icc /I%DAALINCLUDE% daal_test.cpp /Qdaal=sequential

Static linking

On Linux or OS X, Intel DAAL static library files include libdaal_core.a, libdaal_thread.a, and libdaal_sequential.a. On Windows, Intel DAAL static library files include daal_core.lib, daal_thread.lib, and daal_sequential.lib. When linking with parallel Intel DAAL, the runtime libraries of OpenMP (libiomp5) and Intel Threading Building Blocks (libtbb) are also needed

  • On Linux or OS X

    icc -I$DAALINCLUDE daal_test.cpp $DAALLIB/libdaal_core.a $DAALLIB/libdaal_thread.a -liomp5 -ltbb -lpthread -lm
    icc -I$DAALINCLUDE daal_test.cpp $DAALLIB/libdaal_core.a $DAALLIB/libdaal_sequential.a -lpthread -lm
  • On Windows

    icc /I%DAALINCLUDE% daal_test.cpp /Qopenmp /Qtbb %DAALLIB%\daal_core.lib %DAALLIB%\daal_thread.lib 
    icc /I%DAALINCLUDE% daal_test.cpp %DAALLIB%\daal_core.lib %DAALLIB%\daal_sequential.lib

​Linking with GCC 

Dynamic linking

  • On Linux or OS X

    g++ -I$DAALINCLUDE daal_test.cpp -L$DAALLIB -ldaal_core -ldaal_thread -liomp5 -ltbb -lpthread -lm
    g++ -I$DAALINCLUDE daal_test.cpp -L$DAALLIB -ldaal_core -ldaal_sequential -lpthread -lm

​Static linking

  • On Linux or OS X

    g++ -I$DAALINCLUDE daal_test.cpp $DAALLIB/libdaal_core.a $DAALLIB/libdaal_thread.a -liomp5 -ltbb -lpthread -lm
    g++ -I$DAALINCLUDE daal_test.cpp $DAALLIB/libdaal_core.a $DAALLIB/libdaal_sequential.a -lpthread -lm

Running applications built with Intel DAAL

Regardless of linking method, applications linked with Intel DAAL require threading runtime libraries to run. On Linux or OS X systems, make sure the environment variable LD_LIBRARY_PATH contains architecture specific directories with libiomp5.so and libtbb.so. On Windows systems, make sure the environment variable PATH contains architecture specific directories with libiomp5md.dll and tbb.dll

If your application links with dynamic Intel DAAL, then LD_LIBRARY_PATH (Linux and OS X) and PATH (Windows) also need to contain architecture specific directories with DAAL runtime libraries. 

The easiest way of setting up environment properly is to use the scripts provided by Intel DAAL:

  • On Linux or OS X:

    source $DAALROOT/bin/daalvars.sh ia32 (for IA-32 architectures)
    source $DAALROOT/bin/daalvars.sh intel64 (for Intel64 architectures)
  • On Windows:
    %DAALROOT%\bin\daalvars.bat ia32 (for IA-32 architectures)
    %DAALROOT%\bin\daalvars.bat intel64 (for Intel64 architectures)
For more complete information about compiler optimizations, see our Optimization Notice.