dyld: Library not loaded: @rpath error and solution
While compiling some openmp and mkl code I've found the following error
dyld: Library not loaded: @rpath/libmkl_intel_lp64.dylib
I've only used the -O3 and -mkl flgas.
This error has to do with some OS X El Capitan security policies where a plain installation sometimes doesn't load library paths. So you have to source both mklvars.sh and compilervars.sh that are in the /opt/intel/compilers_and_libraries_v/ Where v is the version of your compiler. Lets call that folder /installation_path/. So you source those files with
A couple of times this was all that was necessary but sometimes it failed. I still got that dyld error. So I looked in the forums and they advise you to use the Intel MKL line advisor. The advisor gives you a lot of flags but the one that solved the libmkl_intel_lp64.dylib issue was:
Which is a flag that tells ifort to pass a flag for the linker which shows it the path that is missing.
But then I found the following error:
dyld: Library not loaded: @rpath/libiomp5.dylib
So I searched for the path of libiomp5.dylib library, and added the following flag that the advisor doesn't give you explicitly, but you do the same trick,
And the program is working.
If you find some dyld: Library not loaded errors using openMP and mkl libraries with the -mkl flag; load the paths of compiler libraries sourcing the compiler and mkl vars, then pass the following flags to the compiler at the end of the file list. That is, you can use the following ifort call