Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 569
kirikoumath Avatar asked May 28 '26 08:05

kirikoumath


1 Answers

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.
like image 104
Gilles Avatar answered May 31 '26 23:05

Gilles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!