问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/58029530/how-to-change-path-to-fix-error-main-error-while-loading-shared-library-libm