Compiling and linking MKL with Xcode*

ID 679713
Updated 7/22/2016
Version Latest
Public

author-image

By

 

The following provides the information on linking Intel® Math Kernel Library with Apple* Xcode* development environment. In this article, the Intel Parallel Studio XE 2017 beta with Math Kernel Library 2017 beta and Xcode 7.3.1 will be discussed as an example. 

Step 1: Create new application
Start Xcode and create a new project with OS X » Application » Command Line Tool
New Mac OS application in XcodeI create an application called "MKLDgemmSample". You could copy cblas_dgemmx.cpp, mkl_example.h and common_func.cpp from <MKLROOT>/examples to your application. The <MKLROOT> would be defined as /opt/intel/compilers_and_libraries_2017.0.065/mac/mkl by default.

Step 2: Enable using Intel C/C++ Compiler (ICC) 
Select your application, click “All” & “Combined”, set “build options”-> “Compiler for C/C++/Object C” as ICC Intel C++ Compiler Latest Release.
use Intel C/C++ Compiler
After enabled Intel C/C++ Compiler, more settings based on ICC will come out to display.

Step 3: Set path of Intel MKL and link with MKL

  1. Select “ICC Intel C++ Compiler Latest Release – Performance Library Build Components”, set to Use Intel Math Kernel Library with threaded or non-threaded.
    Use Intel MKL with your application
  2. Select “Search Paths”-> “Header Search Paths”, set as <MKLROOT>/include
    And also select “Search Paths”-> “Library Search Paths” to set as <MKLROOT>/lib
    Add mkl include path
  3. Select “ICC Intel C++ Compiler Latest Release  - Runtime”, set Intel runtime library.
    -Dynamic lib
    -Static lib

    Then, select “Linking”-> “Runpath Search Paths”, add MKL lib path and compiler lib path. The default would be like:
    /opt/intel/compilers_and_libraries_2017.0.065/mac/mkl/lib
    /opt/intel/compilers_and_libraries_2017.0.065/mac/compiler/lib

    set runpath of compiler
  4. “Linking”-> “Other Linker Flags”, add mkl link files. If you set runtime lib as dynamic, then link lib files like below figure.
    link with mkl dynamic/static lib
    For linking with static library, you may want to use 'MKL Link Line Advisor' tool (http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/ ) to determine what set of libraries is more suitable for you. If you planned to use MKL static libraries, please add library file with "xxx.a" extension.(For example: libmkl_core.a, libmkl_intel_thread.a, libmkl_intel_lp64.a ...)

Note1: For the Intel® MKL for Mac OS* package, the Intel® MKL static and dynamic libraries are installed in the same directory / Libraries or /lib. And the static and dynmaic libraries use same name, for example, libmkl_core.dylib and libmkl_core.a . If use -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core, the standard linker used by Xcode* first chooses a dynamic library over a static library.  So if you need to use static, please link to the static libraries by using the full path and library name. e.g $MKLROOT/Libraries/em64t/libmkl_core.a.

Note2: If you link dynamic library for libmkl_intel.dylib, libiomp5.dylib, you may need to set the DYLD_LIBRARY_PATH environment variable in the Xcode environment.

Step 4 (Optional): Set environment variables for MKL
There are two method to set libraries linking path as environment variables:

  • Run shell script file to set environment variables, for example, setting MKL:
    > source /opt/intel/compilers_and_libraries_2017.0.065/mac/mkl/bin/mklvars.sh <ia32|intel64>
  • Or write command to set directly, for example, setting MKL:
    > export DYLD_LIBRARY_PATH="/opt/intel/compilers_and_libraries_2017.0.065/mac/mkl/lib:$DYLD_LIBRARY_PATH

* For linking with OpenMP threading library, please refer the article dyld:Library not loaded:libiomp5.dylib

Since MKL 10.x, Intel Compiler for Mac OS intergate MKL as part of product. 
Please refer to Intel Compiler User and Reference Guide =>Building Applications with Xcode* IDE"
or "Configuring the Apple Xcode* Developer Software to Link with Intel MKL" section in MKL user guide for more details. 

And refer to "Linking Your Application with Intel® MKL" section in the Getting Started document to understand which libraries required by your code.

 Two Samples:

1.  How to link application against Intel MKL using XCode IDE  - Manual link, please see the article: How to link application against Intel MKL using XCode IDE
2.  How to link application against Intel MKL using XCode IDE  - Quick link, please Quick Link Intel® MKL In Xcode* IDE: A Fortran Sample

Operating System:

Mac OS*