How to change path to fix error "./main: error while loading shared library libmkl_core.so?

被刻印的时光 ゝ 提交于 2020-01-25 00:10:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!