distribute shared library with your binary (set rpath)

When a Linux binary is started, the run-time linker uses three sources for finding the needed libraries. First it is possible to set the LD_LIBRARY_PATH environment variable, second the “rpath” (this is a path encoded into the binary while compile time) and last but not least the systems’ default directory like /usr/lib. Now consider the situation where you have to run a binary on a machine where you don’t have root privileges: Here you can’t just install / copy the library to the standard folder, therefore you have to go for one of the first two solutions. Setting the environment variable is seen as bad practice.

Although using rpath is also seen as evil / bad practice, there are situations where you just have no choice. Therefore just copy the shared library into the same folder as your binary (or whatever folder you also distribute) and compile the binary with the following (additional) linker flags:

compile C and C++ code into one binary in Linux




The last line will link the object files together.
A good tutorial is found here.

Compile MATLAB functions in C and link them with Intel MKL CBLAS

The MATLAB utility “mex” (enter “help mex” in command window in MATLAB) is a wrapper for your actual compiler, like gcc. It does not support intels icc. But this is no reason not to use the Intel MKL libraries! Write your code and compile it with:

Looks ugly, but is just a matter of copy pasting from the following website. Then gcc will compile your code and link the Intel libraries! The linking process is somewhat tricky, therefore use


to determine everything after the file name in the compiling command. Remember to select static linking on the website.