1

I have installed intel mkl library. contents have path /home/user/intel/..... . I have to run a C++ code using make file on which it is mentioned.

CC = /home/user/intel/bin/icpc -g
INCLUDE = -I/home/user/intel/mkl/include 
LIB = -L/home/user/intel/mkl/lib/intel64 -lmkl_core -lmkl_intel_lp64 -lmkl_intel_thread -liomp5 -lpthread -std=c++11

I have successfully installed parallel_studio_xe_2019_update5_cluster_edition . but still I'm getting an error message that ./main :error while loading shared libraries. How can I fix this error. What changes I need to do?

9
  • Did you follow the MKL documentation, namely that part for setting environment variables by including a given script (such as mklvars.sh) in your environment? Commented Sep 20, 2019 at 13:55
  • I only run install_GUI.sh in the terminal. But where can I find mklvars.sh intel64 Commented Sep 20, 2019 at 14:09
  • Yes, you should include that script in your Bash session, see here how: How to include file in a bash shell script. A common way is to put this inclusion into a Bash startup script (sucha a ~/.bashrc) to apply it automatically to all Bash sessions. Commented Sep 20, 2019 at 14:11
  • Before running your application, at the shell, try this: export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path/to/your/library Commented Sep 20, 2019 at 14:14
  • For me its hard to grasp this explanation. Can you please explain it with some easy language.I compile my code simply by writing make, what will be /path/to/your/library in my case ? Commented Sep 20, 2019 at 14:20

1 Answer 1

3

Linking with shared libraries is actually done in two steps: When building (where the linker needs to find the library); And when running (when the operating system dynamic loaded needs to find the library).

When building with libraries installed in non-standard locations, you tell the linker where to find the library using the -L option. Unfortunately it doesn't tell the dynamic loader where the library is located.

To tell the dynamic loader the location of a dynamic library there are a couple of way, the one I recommend is to add a flag when building so the linker will embed the location inside the executable program file for the dynamic loader to see. This is done with the option -Wl,-rpath,/path/to/lib/directory.

In your case you need to add the option -Wl,-rpath,/home/user/intel/mkl/lib/intel64 to the LIB makefile variable.


To clarify, the full line should be

LIB = -L/home/user/intel/mkl/lib/intel64 -Wl,-rpath,/home/user/intel/mkl/lib/intel64 -lmkl_core -lmkl_intel_lp64 -lmkl_intel_thread -liomp5 -lpthread -std=c++11 

That is, you need both the old -L option (as you current have it in the code you show) and add the new option.

Sign up to request clarification or add additional context in comments.

7 Comments

But then how and where should I need to define rpath?
@huda_ Almost, -Wl with l as in lower-case L. And you still need the -L option for the linker to find the libraries.
I edited like this: LIB = -L//-Wl,rpath//home/tqc04/intel/mkl/lib/intel64 -lmkl_core -lmkl_intel_lp64 -lmkl_intel_thread -liomp5 -lpthread -std=c++11 . But still can't fix this error.I never met with such type of problem. I mistakenly deleted some files in home directory after which i'm facing this problem
@huda_ You're misunderstanding what I mean. See my updated answer
I mentioned that line but still getting same error.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.