Search code examples
matlabmexmatlab-compiler

error while compiling using mex in matalb in linux


I am using some instruction provided by code developer to compile the library. However i am getting the error as shown in the figure. Does anybody has any idea about this? It is my first time to use mex

mex LDFLAGS="\$LDFLAGS -Wl,-rpath,\." nativeborg.cpp libborg.so

I was trying to compile using mex in matlab in linux.

enter image description here


Solution

  • mex doesn't directly recognize C++ compiler or linker options. You have two options:

    1. Once and for all, modify the compiler options .xml file in your matlab settings. For example on linux this file is called mex_C++_glnxa64.xml.
    2. Temporarily append options to existing options:

      mex CXXFLAGS=['$CXXFLAGS, 'your compiler options string'] filename

      mex LDFLAGS=['$LDFLAGS, 'your linker options string'] filename

    Both depend on what platform you are using. For example on windows you have to use COMPFLAGS instead of CXXFLAGS. The advantage of (1) is that it is already set to use the correct option names for the platform. See "Override Default Compiler Switch" in the "mex" documentation.