I used the Matlab Library Compiler to access Matlab functions from a C++ shared library.
When instantiating ArrayFactory, the execution either hangs or throws the exception "attempted to assign clientFactoryFuncPtr twice to different values"; the behavior depends on when ArrayFactory is instantiated.
Calling initMATLABLibrary() doesn't seem to create any issues. Also compiling and executing a sample cpp program created with the Library Compiler works, hence I don't think there is a general problem with my build environment.
The following function is called by matlab::cpplib::runMain():
int f(std::shared_ptr<matlab::cpplib::MATLABApplication> app, const int argc, const char * argv[]){ try { // Throws exception matlab::data::ArrayFactory factory; auto ml = matlab::cpplib::initMATLABLibrary(app, u"libmatlab_procesing.ctf"); // Instantiation after initMATLABLibrary() hangs, but no exception is thrown //matlab::data::ArrayFactory factory; // ... } catch(const std::exception & exc) { std::cerr << exc.what() << std::endl; return -1; } return 0;}
Is there any explanation for the behavior of ArrayFactory?
Best Answer