Building a Matlab Engine application with Qt Framework
Show older comments
Hello,
I am having problems compiling Matlab Engine libraries with a small qt application. I have tried using Matlab 2016b, 2017a and 2017b. I am using Ubuntu 16.04, gcc 5.4.0 (and gcc 4.9) and Qt 5.10.0.
The example I am providing is using Matlab 2017a, but I have the same issue when I use 2017b and 2016b. The application I am trying to compile is the following
#include <QcoreApplication>
#include <QDebug>
#include "engine.h"
#include "matrix.h"
int main(int argc, char *argv[])
{
Engine* m_engine;
m_engine = engOpen("");
if (!(m_engine = engOpen(""))) {
qDebug()<<"\nCan't start MATLAB engine\n";
exit(-1);
}
}
My Qmake .pro file is :
MATLAB_ROOT_PATH = /usr/local/MATLAB/R2017a
MATLAB_INCLUDE_PATH = $${MATLAB_ROOT_PATH}/extern/include
MATLAB_LIB_PATH = $${MATLAB_ROOT_PATH}/bin/glnxa64
MATLAB_SYS_DIR = $${MATLAB_ROOT_PATH}/sys/os/glnxa64
LIBS += -L$${MATLAB_LIB_PATH} -lmx -lmex -lmat -lm -leng
LIBS += -L$${MATLAB_SYS_DIR} -lstdc++
INCLUDEPATH += $$MATLAB_INCLUDE_PATH
DEPENDPATH += $$MATLAB_INCLUDE_PATH
QMAKE_RPATHDIR += $$MATLAB_LIB_PATH
QMAKE_RPATHDIR += $$MATLAB_SYS_DIR
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
Compiling the code above results in the following runtime error :
./matlab_test: /usr/local/MATLAB/R2017a/bin/glnxa64/libQt5Core.so.5: no version information available (required by ./matlab_test)
./matlab_test: /usr/local/MATLAB/R2017a/bin/glnxa64/libQt5Core.so.5: no version information available (required by ./matlab_test)
./matlab_test: relocation error: ./matlab_test: symbol qt_version_tag, version Qt_5.10 not defined in file libQt5Core.so.5 with link time reference
I have seen in the documentation that gcc 4.9 is only supported, but I get the same error. I have tried changing the libraries I link and the result is again the same. In order to solve the above error I add the Qt library directory to the QMAKE_RPATHDIR
QMAKE_RPATHDIR += $$QT_LIB_DIR \
which then results in the following compilation error
/usr/local/MATLAB/R2017b/bin/glnxa64/libmwi18n.so: undefined reference to `icu_56::UnicodeString::UnicodeString(char16_t const*, int)'
/usr/local/MATLAB/R2017b/bin/glnxa64/libmwi18n.so: undefined reference to `UCNV_FROM_U_CALLBACK_ESCAPE_WITH_INVISIBLE_CHARS_56'
/usr/local/MATLAB/R2017b/bin/glnxa64/libmwi18n.so: undefined reference to `UCNV_FROM_U_CALLBACK_STOP_WITH_INVISIBLE_CHARS_56'
/usr/local/MATLAB/R2017b/bin/glnxa64/libmwi18n.so: undefined reference to `icu_56::UnicodeString::UnicodeString(char16_t const*)'
/usr/local/MATLAB/R2017b/bin/glnxa64/libmwi18n.so: undefined reference to `icu_56::UnicodeString::doCompare(int, int, char16_t const*, int, int) const'
I have seen there is an issue with the stdc++ library that is included with the Matlab installation, which after replacing I still get the error above relating to the libmwi18n.so.
Finally I have tried using the MatlabEngine.so which are included only with Matlab 2017b. Using this library and linking with the libstdc++ of the compiler, I am able to compile, but I get the runtime error :
/usr/local/MATLAB/R2017b/bin/glnxa64/libicuio.so.56: undefined symbol: _ZN6icu_5613UnicodeString8doAppendEPKDsii
I am not sure if it is a compiler issue, since I am using both g++-4.9 and the one provided with Ubuntu 16.04.
2 Comments
Vincent Hui
on 15 Feb 2018
Hi,
I have tried using the MatlabEngine.so with Qt 5.10.1 too. The same runtime error I got:
/opt/MATLAB/R2017b/bin/glnxa64/libicuio.so.56: undefined symbol: _ZN6icu_5613UnicodeString8doAppendEPKDsii
How to slove the problem?
Thanks
Walter Roberson
on 15 Feb 2018
That name demangles to
icu_56::UnicodeString::doAppend(char16_t const*, int, int)
Answers (1)
Categories
Find more on COM Component Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!