I have a bunch of C++ code that I'd like to call from Matlab. I compile the code into a shared library, make a small mex interface, and compile that with mex while linking to the .so.
Basically, I have a CMake file with
add_library(mylibrary SHARED <dependencies>)
which i compile with
(optionally export CXX=clang++); cmake ..; make
and call mex with
mex -lmylibrary [...]
This works fine if I compile the original code with g++. If I try to use clang++ (exact same flags etc), however, the mex compilation still runs fine but upon trying to call the function in matlab I get the error
Invalid MEX-file '<path_to_file>.mexa64': dlopen: cannot load any more object with static TLS
This isn't a huge issue obviously because I can just use g++, but I'd prefer to use clang if possible because the compilation is quite a bit faster and the warnings/errors are nicer.