Matlab exception thrown by initialization of mwArray while using c++ shared library

Hello All,
I've been struggling to succeed in using mwArrays in a c++ application with a shared library compiled with matlab compiler. I created a simple function to identify a system in using the system identification toolbox and both the n4sid and pem functions. Currently, I get a fatal error whenever I initialize a mwArray. The exception is thrown in the matlab mclcppclass.h file.:
mwArray GetPromoted(mwSize num_indices, ...)
{
va_list vargs;
va_start(vargs, num_indices);
array_ref* p = array_ref_getV_int(m_pa, num_indices, vargs);
va_end(vargs);
if (!p)
mwException::raise_error();
return mwArray(p);
}
the minimal program is:
#include "libidentify_system.h"
int main()
{
mclInitializeApplication(NULL,0);
mwArray test;
test(1, 1, mxDOUBLE_CLASS);
return 0;
}
libidentify_system.h is the .h file generated by MATLAB compiler.
I'm currently compiling using cmake. The relevant lines in the top level cmakelists.txt file are:
cmake_minimum_required(VERSION 3.5.1)
project(MPC_IAT)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow \
-Wnon-virtual-dtor -Wpedantic -Wold-style-cast -Wcast-align -Wunused \
-Wconversion -Woverloaded-virtual -Wsign-conversion \
-Wlogical-op \
-Wuseless-cast -Wdouble-promotion -Wformat=2 -Wno-format-y2k")
include_directories("/usr/local/MATLAB/R2020b/extern/include")
find_package(Threads)
link_directories("/usr/local/MATLAB/R2020b/runtime/glnxa64")
link_directories("/usr/local/MATLAB/R2020b/extern/bin/glnxa64")
add_library(libidentify_system SHARED IMPORTED)
set_property(TARGET libidentify_system PROPERTY IMPORTED_LOCATION "/usr/libidentify_system/application/libidentify_system.so")
add_executable(test
src/testmw/main.cpp
src/testmw/libidentify_system.h)
target_link_libraries(test libidentify_system mwmclmcrrt MatlabDataArray MatlabCppSharedLib ${CMAKE_THREAD_LIBS_INIT})
I'm still pretty new to c++ and cmake so I suspect the error has more to do with incorrect linking or something of that sort. I figure here is not the place to put the whole shared set of files that result from compiling my script, but I've put the stuff in a zip located here (my google drive).

 Respuesta aceptada

Jonathan Ingber Katz
Jonathan Ingber Katz el 15 de Nov. de 2020
Editada: Jonathan Ingber Katz el 15 de Nov. de 2020
The solution was a missing call to mclmcrInitialize() in main.

Más respuestas (0)

Categorías

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by