Matlab Engine Application with Qt

  • Hello everyone,

    I am trying to create a Qt application that uses the Matlab engine to perform calculations and execute scripts.
    My build system has the following parameters that I think are relevant :

    Matlab 2017a
    Ubuntu 16.04
    gcc 5.4.0

    The application I am currently trying to compile is very simple

    #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";

    The pro file I am using is the following :

    QT -= gui
    CONFIG += c++11
    CONFIG -= app_bundle
    MATLAB_ROOT_PATH = /usr/local/MATLAB/R2017a
    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++
    SOURCES += main.cpp

    The above code compiles, but I get the following error during execution from both the Qt Creator and the system console :

    ./matlab_test: /usr/local/MATLAB/R2017a/bin/glnxa64/ no version information available (required by ./matlab_test)
    ./matlab_test: /usr/local/MATLAB/R2017a/bin/glnxa64/ 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 with link time reference

    I have looked into this problem for a while now and problem was that I received runtime error regarding the stdc++ library which was not the same as the compilers.

    Replacing the linking to the stdc++ library with the following

    LIBS += -L/usr/lib/x86_64-linux-gnu -lstdc++

    results in the following compilation error :

    g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_CORE_LIB -I../matlab_test -I. -I/usr/local/MATLAB/R2017a/extern/include -I../../../../Qt/5.10.0/gcc_64/include -I../../../../Qt/5.10.0/gcc_64/include/QtCore -I. -I../../../../Qt/5.10.0/gcc_64/mkspecs/linux-g++ -o main.o 
    g++ -Wl,-O1 -Wl,-rpath,/home/stef/Qt/5.10.0/gcc_64/lib -Wl,-rpath,/usr/lib/x86_64-linux-gnu -Wl,-rpath,/usr/local/MATLAB/R2017a/bin/glnxa64 -Wl,-rpath,/usr/local/MATLAB/R2017a/sys/os/glnxa64 -Wl,-rpath,/home/stef/Qt/5.10.0/gcc_64/lib -o matlab_test main.o   -L/usr/local/MATLAB/R2017a/bin/glnxa64 -lmx -lmex -lmat -lm -leng -L/usr/lib/x86_64-linux-gnu -lstdc++ -L/home/stef/Qt/5.10.0/gcc_64/lib -lQt5Core -lpthread 
    /usr/local/MATLAB/R2017a/bin/glnxa64/ undefined reference to `icu_56::UnicodeString::UnicodeString(char16_t const*, int)'
    /usr/local/MATLAB/R2017a/bin/glnxa64/ undefined reference to `UCNV_FROM_U_CALLBACK_ESCAPE_WITH_INVISIBLE_CHARS_56'
    /usr/local/MATLAB/R2017a/bin/glnxa64/ undefined reference to `UCNV_FROM_U_CALLBACK_STOP_WITH_INVISIBLE_CHARS_56'
    /usr/local/MATLAB/R2017a/bin/glnxa64/ undefined reference to `icu_56::UnicodeString::UnicodeString(char16_t const*)'
    /usr/local/MATLAB/R2017a/bin/glnxa64/ undefined reference to `icu_56::UnicodeString::doCompare(int, int, char16_t const*, int, int) const'
    Makefile:244: recipe for target 'matlab_test' failed
    collect2: error: ld returned 1 exit status
    make: *** [matlab_test] Error 1
    16:18:26: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project matlab_test (kit: Desktop Qt 5.10.0 GCC 64bit)
    When executing step "Make"

    Mathworks states that they officially support gcc 4.9, but I think this is true when compiling from MATLAB directly. I have also tried compiling by linking the libraries in the Matlab folder to the system ones instead, but I get similar errors.

    Anyone have any idea? Do you think it is a compiler issue? Do you think it could be solved by compiling Qt with gcc 4.9 and then trying again? Am I not linking the libraries correctly in the qmake .pro file?

    Thank you for your time

    PS : The ldd command on the executable when I can get it to compile gives me the following =>  (0x00007ffc42980000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992c48b000) => /usr/local/MATLAB/R2017a/sys/os/glnxa64/ (0x00007f992c178000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992ba41000) => /usr/local/MATLAB/R2017a/sys/os/glnxa64/ (0x00007f992b82b000) => /lib/x86_64-linux-gnu/ (0x00007f992b449000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992b165000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992add3000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992ab78000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992a975000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992a757000) => /lib/x86_64-linux-gnu/ (0x00007f992a44d000) => /lib/x86_64-linux-gnu/ (0x00007f992a230000)
    /lib64/ (0x000055e67200a000) => /lib/x86_64-linux-gnu/ (0x00007f992a016000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9929b8e000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99297f1000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9927e0b000) => /lib/x86_64-linux-gnu/ (0x00007f9927c06000) => /lib/x86_64-linux-gnu/ (0x00007f99279fe000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99276ac000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99272f9000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99270f7000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9926ed6000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9926ccf000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9926abe000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99268a8000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99265ca000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99262ba000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9926099000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9925e70000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9925c63000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9925a18000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99257c5000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99255af000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f992537e000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9924eed000) => /lib/x86_64-linux-gnu/ (0x00007f9924cb4000) => /lib/x86_64-linux-gnu/ (0x00007f9924aa6000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9924846000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9924626000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f99243b5000) => /usr/local/MATLAB/R2017a/bin/glnxa64/ (0x00007f9923f6e000) => /lib/x86_64-linux-gnu/ (0x00007f9923d46000)

  • According to Mathworks "Build C++ Engine Programs" the following libraries should be used in Linux:

    Linux Libraries
    Engine library — matlabroot/extern/bin/glnxa64/
    MATLAB Data Array library — matlabroot/extern/bin/glnxa64/
    Additional library — pthread

    Could it be in your pro file you need to add extern to this path?

    MATLAB_LIB_PATH = $${MATLAB_ROOT_PATH}/bin/glnxa64

  • @shwoods said in Matlab Engine Application with Qt:


    These libraries were included with MATLAB 2017b. The previous MATLAB versions use the engine.h and matrix.h.

    I have been in contact with mathworks and as a first step towards solving the problem was to use Qt 5.5 while linking to the located in the $$MATLAB_SYS_DIR. The problem then is that matlab engine does not start.

    I will update you if I find more

  • Qt Champions 2017

    You must likely have checked that but just in case.
    Did you try LDD on libMatlabEngine to see if anything missing ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.