How to build IPP application in Linux environment


Introduction

Below we will give an example on how to build an IPP project in Linux within two steps.

Prerequisite: $source <ipp install path>/em64t/tools/env/ippvarsem64t.sh

  • Required Software installed: Intel® IPP library install package: l_ipp_p_x_x.x.xxx.tgz
  • Supported Compiler: gcc, g++ and related tools or Intel® C++ Compiler version for Linux* OS for IA-32 processors and Intel 64 processors (optional).

 

Please note that  the latest IPP version(IPP 7.0 Update 2)changed the library name and library directories: New Directory Structure and Library Naming Scheme for Intel® IPP 7.0 Library 
You may change the library name and path correspondingly.  

The library is available as a stand-alone product or as a component in Intel® Parallel Studio 2011, Intel® Parallel Studio XE 2011, Intel® C++ Studio XE 2011, Intel® Composer XE 2011, and Intel® C++ Composer XE 2011. Please visit the Intel® Software Evaluation Center to download evaluation versions of these and other Intel software products.


 

Step 1 – Call Intel® IPP Functions

Calling Intel IPP functions is as simple as calling any other C functions. Include the relevant header file (ex. ipp.h) and then call the function with correct parameters.

The example code is as follows:

#include “ipp.h”
void main()
{
IppiSize roi = {5,4};
Ipp8u x[8*4] = {0};
ippiSet_8u_C1R(1, x,8, roi); //call ippiSet_8u_C1R() function in ipp.h
}

 

Save this file as main.c.


Step 2 – Build Intel® IPP Projects

Build using gcc in command line. We will take Intel IPP 64bit as an example:

  • Set environment:                                        export ipp_install_path="/opt/intel/ipp/6.1.x"
  • For dynamic link, the command is:             $gcc -o main main.c -I <ipp install path>/em64t/include -L <ipp install path>/em64t/sharedlib -lippiem64t -lippsem64t -lippcoreem64t -liomp5 -lpthread -lm
  • For static link, the command is:                  $gcc -o main main.c -I <ipp install path>/em64t/include -L <ipp install path>/em64t/lib -lippiemergedem64t -lippimergedem64t -lippsemergedem64t -lippsmergedem64t -lippcoreem64t -lpthread
  • For threaded static link,  the command is   $gcc -o main main.c -I <ipp install path>/em64t/include -L <ipp install path>/em64t/lib -lippimergedem64t -lippimergedem64t_t -lippsmergedem64t -lippsmergedem64t_t -lippcoreem64t_t.a -liomp5 -lpthread

To see why we link these libraries in the command and to clarify the problem which libraries should be linked for my own project, you can refer to Library dependencies by domain.

If you build successfully, you can get the executable file: main.

*Note 1: <ipp install path> is the path where your IPP is installed, e.g. /opt/intel/ipp/6.x/, /opt/intel/Compiler/11.x/0xx/ipp/. 

*Note 2: The article command sample is for Intel 64 application.  For IA32 application, the command is same: 
-I <ipp install path>/ia32/include -L <ipp install path>/ia32/sharedlib -lippi -lipps -lippcore -liomp5 -lpthread -lm

*Note 3: As Which version of Intel IPP, Intel MKL and Intel TBB is installed by the Intel® Compiler Professional Edition? mentions, Intel Compiler Professional Edition have IPP as a component . At the same time, Intel Compiler provide a compile option -ipp instead linking ipp manually, thus if using Intel Compiler Professional Edition, the build command become simple:
$icc *.c -ipp


Step 3 - Run Intel® IPP Binary 

If using the Intel® IPP shared libraries, you need to add the path to the libraries to the system variable LD_LIBRARY_PATH by either using the shell script or manually setting the environment.

  • Use the Intel IPP shell script to set the required environment variables for shared library dispatching and building code samples:
    • Open a Terminal.
    • Navigate to the Intel IPP directory /tools/env.
    • Type source ippvars32.sh ( or ippvarsem64t.sh for Intel® 64 processors)

 Manually set the environment variable:

    • Open a Terminal.
    • If the libraries are in the /opt/intel/ipp/X.X/ia32/sharedlib folder, and then type export LD_LIBRARY_PATH=/opt/intel/ipp/X.X/ia32/sharedlib:$LD_LIBRARY_PATH

 


 

Common error messages

  • Error message: main.c:(.text+0x49): undefined reference to `ippiSet_8u_C1R'
    1. Make sure to link all dependent libraries. To solve the problem above, you should check your build command to see if it contains the library, "-lippiem64t".
    2. Make sure to link the libraries in appropriate order. For example, if your command contains both "-lippiemergedem64t" and "-lippimergedem64t". Make sure to put "-lippiemergedem64t" before "-lippimergedem64t" in command, otherwise you will get this "undefined reference" either.
  • Error message: /opt/intel/ipp/6.0.0.045/em64t/sharedlib/libiomp5.so: undefined reference to `pthread_atfork'
    • Please make sure to link "-lpthread" library in your command line.Error message: /opt/intel/ipp/6.0.0.045/em64t/lib/libippiemergedem64t.a(ippi02496as.o): In function `ippiSet_8u_C1R': (.text+0x3): undefined reference to `ippJumpIndexForMergedLibs' 
        If your command line links libraries from <ipp install path>/em64t/lib, please make sure to contain "-lippcoreem64t" library.
  • Other libiomp5 error: OpenMP run time library like libiomp5.so is provided by Intel® Compiler. It may locate in Compiler directory: OpenMP Run-time Libraries Changed since Intel IPP 6.0 and Intel MKL 10.1
  •  http://software.intel.com/en-us/articles/xcode-link-error-file-not-found-libiomp5dylib/

如需更全面地了解编译器优化,请参阅优化注意事项