kirikoumath
kirikoumath

Reputation: 733

explicitly link intel icpc openmp

I have the intel compiler install at the following $HOME/tpl/intel. When I compile a simple hello_omp.cpp with openMP enabled

#include <omp.h>
#include <iostream>

int main ()
{
#pragma omp parallel

    {
        std::cout << "Hello World" << std::endl;
    }
    return 0;
}

I compile with ~/tpl/intel/bin/icpc -O3 -qopenmp hello_omp.cpp but when I run I get the following error: ./a.out: error while loading shared libraries: libiomp5.so: cannot open shared object file: No such file or directory.

I would like to explicitly link the intel compiler and the appropriate library during the make process without using the LD_LIBRARY_PATH?

Upvotes: 3

Views: 1953

Answers (2)

Anoop - Intel
Anoop - Intel

Reputation: 354

Intel Compiler ships compilervars.sh script in the bin directory which when sourced will set the appropriate env variables like LD_LIBRARY_PATH, LIBRARY_PATH and PATH with the right directories which host OpenMP runtime library and other compiler specific libraries like libsvml (short vector math library) or libimf (more optimized version of libm).

Upvotes: 0

Gilles
Gilles

Reputation: 9499

You have 2 simple solutions for your problem:

  1. Linking statically with the Intel run time libraries:
    ~/tpl/intel/bin/icpc -O3 -qopenmp -static_intel hello_omp.cpp
    • Pros: you don't have to care where the Intel run time environment is installed on the machine where you run the binary, or even having it installed altogether;
    • Cons: your binary becomes bigger and won't allow to select a different (more recent ideally) run time environment even when it is available.
  2. Adding the search path for dynamic library into the binary using the linker option -rpath:
    ~/tpl/intel/bin/icpc -O3 -qopenmp -Wl,-rpath=$HOME/tpl/intel/lib/intel64 hello_omp.cpp
    Notice the use of -Wl, to transmit the option to the linker.
    I guess that is more like what you were after than the first solution I proposed so I let you devise what the pros and cons are for you in comparison.

Upvotes: 2

Related Questions