dyld:Library not loaded:libiomp5.dylib

 

Problem : 

Build an Intel® MKL program on Mac OS* with Intel® Fortran Compiler,

For example, m_cprof_p_11.1.076,
MKLPATH=/opt/intel/Compiler/11.1/076/Frameworks/mkl/lib/em64t
MKLINCLUDE=/opt/intel/Compiler/11.1/076/Frameworks/mkl/include
> ifort  main. f -o  main -L$(MKLPATH) -I$(MKLINCLUDE) -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core  -lpthread 

get compiler warning:
ld64 warning: indirect library libiomp5.dylib could not be loaded: file not found: libiomp5.dylib

Or runtime error:
dyld: Library not loaded: libiomp5.dylib
  Referenced from: /opt/intel/Compiler/11.1/076/Frameworks/mkl/lib/em64t/libmkl_intel_thread.dylib
  Reason: image not found
Trace/BPT trap


Root Cause : 
Since MKL 10.0, the MKL libraries for Mac OS* have been integrated into Intel® C++/Fortran Compiler Professional Edition or Intel® C++/Fortran Composer XE for Mac OS* X. The default path of MKL libraries were changed from 
"/Library/Frameworks/Intel_MKL.framework/Versions/10.0.x.xxx/"  
to "/opt/intel/Compiler/11.x/0xx/Frameworks/mkl/"  

At the same time, the default OpenMP libraries (libiomp5.dylib, libiomp5.a) used by MKL are not in <MKL Libraries>/lib directory as in previous versions. They are under the Intel compiler lib directory now. 
for example,  in /opt/intel/Compiler/11.0/0xx/lib

(IPP is the same, please see the article XCode link error: "file not found: libiomp5.dylib" )

Resolution : 
For compiler warning:
Please refer to the MKL link line advisor.
the command line could be
>ifort  main. f -o  main -L$(MKLPATH) -I$(MKLINCLUDE) -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -openmp -lpthread 

or
ifort  main. f -o  main -L$(MKLPATH) -I$(MKLINCLUDE) -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core 
-L/opt/intel/Compiler/11.1/076/lib -liomp5 -lpthread 

For runtime error:  like dyld: Library not loaded: lib[mkl|ipp]_x.dylib

Please add the path of lib*.dylib in system environment before run binary.
>export DYLD_LIBRARY_PATH="/opt/intel/Compiler/11.1/076/lib:$DYLD_LIBRARY_PATH"

In Xcode 2.3 development environment,
Under Executables, Double click active Executable, click "Arguments" Tab, under Variables to be set in the environment, Add DYLD_LIBRARY_PATH , set value, for example,
/opt/intel/Compiler/11.1/076/lib:/opt/intel/Compiler/11.1/080/Frameworks/mkl/lib/em64t

In latest release, Intel compiler, MKL are installed to /opt/intel/composer_xe_2013_sp1.1.103, so the environment variable DYLD_LIBRARY_PATH should be setted as 

>export DYLD_LIBRARY_PATH="/opt/intel/composer_xe_2013_sp1.1.103/compiler/lib":$DYLD_LIBRARY_PATH

or run the script 

>source  source /opt/intel/composer_xe_2013_sp1.1.103/bin/compilervars.sh intel64

and the result is like 

echo $DYLD_LIBRARY_PATH
/opt/intel/composer_xe_2013_sp1.1.103/compiler/lib:/opt/intel/composer_xe_2013_sp1.1.103/compiler/lib/intel64:/opt/intel/composer_xe_2013_sp1.1.103/ipp/../compiler/lib:/opt/intel/composer_xe_2013_sp1.1.103/ipp/lib:/opt/intel/composer_xe_2013_sp1.1.103/compiler/lib:/opt/intel/composer_xe_2013_sp1.1.103/mkl/lib:/opt/intel/composer_xe_2013_sp1.1.103/tbb/lib

 

For more complete information about compiler optimizations, see our Optimization Notice.