How to link ZeroMQ when compiling Matlab/Simulink S-function via 'mex'

When you compile a Matlab or Simulink S-Function using mex, this is how you can link the ZeroMQ library:

First, try whether it works without explicit include and library paths:

mex -lzmq mysfunction.cpp

If you use czmq in addition to zeromq, you can link both libraries like this:

mex -lzmq -lczmq mysfunction.cpp

If you use cppzmq (C++ bindings for ZeroMQ), this is a header-only library hence you don’t need to link it.

Explicitly specifying include and library paths

If that doesn’t work, you can specify the include and library paths like this:

mex -I/path/to/zeromq/include -L/path/to/zeromq/lib -lzmq myfunction.cpp

for example:

mex -I$HOME/usr/include -L$HOME/usr/lib -lzmq myfunction.cpp