Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Configure matlab engine in qtcreator
Forum Updated to NodeBB v4.3 + New Features

Configure matlab engine in qtcreator

Scheduled Pinned Locked Moved Solved 3rd Party Software
matlab
14 Posts 4 Posters 6.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zhitoune
    wrote on last edited by A Former User
    #1

    Dear all,

    I'm facing a problem trying to realize a software in qt that can call matlab function and scripts. But so far I'm miserably failing at setting up my code with matlab libraries and header.
    In order to work I need to include 2 header : engine.h and matrix.h
    and 2 library : libmx.lib and libeng.lib
    so here is my .pro

    QT += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = testMatlabEngine
    TEMPLATE = app
    
    SOURCES += main.cpp \
            mainwindow.cpp
    
    HEADERS  += mainwindow.h \
                engine.h \
                matrix.h
    
    DISTFILES += \
        codeMatlab.m
    
    win32:LIBS += -Lc:\matlab\r2017a\extern\lib\win64\microsoft -leng
                  -LC:\MATLAB\R2017a\extern\lib\win64\microsoft -lmx
    
    INCLUDEPATH += "c:/matlab/r2017b/extern/include"
                   "c:/matlab/r2017b/extern/lib/win64/microsoft"
    

    and so far even if the autocompletion of qtCreator recognize matlab function such as "engEvalString" I get the folowing warnings :
    warning: Failure to find: engine.h
    warning: Failure to find: matrix.h
    and the following error
    error: cannot find -leng

    any idea on how to make it work, I'm running out of idea

    edit : I forgot to mention that I'm using window 7

    tekojoT 1 Reply Last reply
    0
    • Z Zhitoune

      Dear all,

      I'm facing a problem trying to realize a software in qt that can call matlab function and scripts. But so far I'm miserably failing at setting up my code with matlab libraries and header.
      In order to work I need to include 2 header : engine.h and matrix.h
      and 2 library : libmx.lib and libeng.lib
      so here is my .pro

      QT += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = testMatlabEngine
      TEMPLATE = app
      
      SOURCES += main.cpp \
              mainwindow.cpp
      
      HEADERS  += mainwindow.h \
                  engine.h \
                  matrix.h
      
      DISTFILES += \
          codeMatlab.m
      
      win32:LIBS += -Lc:\matlab\r2017a\extern\lib\win64\microsoft -leng
                    -LC:\MATLAB\R2017a\extern\lib\win64\microsoft -lmx
      
      INCLUDEPATH += "c:/matlab/r2017b/extern/include"
                     "c:/matlab/r2017b/extern/lib/win64/microsoft"
      

      and so far even if the autocompletion of qtCreator recognize matlab function such as "engEvalString" I get the folowing warnings :
      warning: Failure to find: engine.h
      warning: Failure to find: matrix.h
      and the following error
      error: cannot find -leng

      any idea on how to make it work, I'm running out of idea

      edit : I forgot to mention that I'm using window 7

      tekojoT Offline
      tekojoT Offline
      tekojo
      wrote on last edited by
      #2

      Hi @Zhitoune
      You are at least missing the \ in the line ends of win32:libs and includepath.
      And windows paths need to be in "" so

      win32:LIBS += -L"c:\matlab\r2017a\extern\lib\win64\microsoft" -leng \
                    -L"c:\MATLAB\R2017a\extern\lib\win64\microsoft" -lmx
      

      and

      INCLUDEPATH += "c:/matlab/r2017b/extern/include" \
                     "c:/matlab/r2017b/extern/lib/win64/microsoft"
      
      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zhitoune
        wrote on last edited by
        #3

        Thanks @tekojo

        unfortunatly, it still does not compile...
        I have tried many variations like removing upper case etc etc but so far with no results

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          Zhitoune
          wrote on last edited by
          #4

          So using :

          LIBS += "C:\MATLAB\R2017b\extern\lib\win64\mingw64\libeng.lib" \
                  "C:\MATLAB\R2017b\extern\lib\win64\mingw64\libmx.lib"
          

          I somewhtat manage to go to :

          error: undefined reference to `engOpen'
          

          (engOpen being a fonction of matlab engine.h ) wich I interpret as : " the headers are fine but it' s a reference to an unknown library".
          I checked and I use MinGW 5.3 wich is compatible with my version of matlab

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Aren't you mixing 32 and 64 bit MinGW ?

            By the you should rather use forward slashes everywhere. Qt handles the conversion for you. Otherwise use double backslashes.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • Z Offline
              Z Offline
              Zhitoune
              wrote on last edited by Zhitoune
              #6

              Thanks for you help!
              that's what I'm trying to determine. I'll post when I know more

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zhitoune
                wrote on last edited by
                #7

                So I checked and it seem that the matlab libraries were compiled using minGW-w64 while I'm using minGW 5.3 32 bit. Can the errors I obtain be the results of this imcompatibility?
                So I configured a new kit with MSVC2015 64bit compiler but I get the following error :

                mainwindow.obj:-1: error: LNK2019: unresolved external symbol engOpen referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
                
                mrjjM 1 Reply Last reply
                0
                • Z Zhitoune

                  So I checked and it seem that the matlab libraries were compiled using minGW-w64 while I'm using minGW 5.3 32 bit. Can the errors I obtain be the results of this imcompatibility?
                  So I configured a new kit with MSVC2015 64bit compiler but I get the following error :

                  mainwindow.obj:-1: error: LNK2019: unresolved external symbol engOpen referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
                  
                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Zhitoune
                  Make sure to completely wipe the build folder and
                  run qmake and rebuild all.

                  1 Reply Last reply
                  1
                  • Z Offline
                    Z Offline
                    Zhitoune
                    wrote on last edited by
                    #9

                    thanks for your help,

                    I always use rebuild. should I clean and rebuild?

                    mrjjM 1 Reply Last reply
                    0
                    • Z Zhitoune

                      thanks for your help,

                      I always use rebuild. should I clean and rebuild?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @Zhitoune
                      well to be 100% sure, please delete the build folder. ( in this case)
                      This is normally not needed but if anything remains from the minGw compile and u now are using visual studio then odd errors will pop up.
                      ( the .o files should in other folder, but better sure than sorry)

                      Often rebuild is enough but sometimes full deletion is needed.
                      Update:
                      Sorry, i misread.
                      it complains about engOpen
                      which i assume is from the MATLAB lib

                      1 Reply Last reply
                      1
                      • Z Offline
                        Z Offline
                        Zhitoune
                        wrote on last edited by
                        #11

                        yes it is!

                        mrjjM 1 Reply Last reply
                        0
                        • Z Zhitoune

                          yes it is!

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #12

                          @Zhitoune
                          And the MATLAB r2017b libraries are compiled with 2015/2017 64 bit ?

                          Higher up you show
                          C:\MATLAB\R2017b\extern\lib\win64\mingw64\libeng.lib"

                          but maybe it also contains libs for visual studio in other folder than mingw64 ?

                          Ah yes, seems to be in
                          c:\matlab\r2017a\extern\lib\win64\microsoft

                          So those are 2015/2015 compiled?

                          You cannot fix DLLS from other compilers. It must be same compiler for App and
                          matlab libs.

                          So mingw32 wont load 64 bit mingw.

                          but so we are clear.

                          You are now using
                          MSVC2015 compiler (installed by your self)
                          Qt 2015 version kit
                          and points to
                          win32:LIBS += -L"c:\matlab\r2017a\extern\lib\win64\microsoft" -leng
                          -L"c:\MATLAB\R2017a\extern\lib\win64\microsoft" -lmx

                          from .pro file?

                          1 Reply Last reply
                          0
                          • Z Offline
                            Z Offline
                            Zhitoune
                            wrote on last edited by
                            #13

                            So it's finaly working with a kit made of :
                            Desktop Qt 5.9.2
                            MSVC2015 64bit

                            and my .pro file looks like this :

                            QT += core gui
                            
                            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                            
                            TARGET = testMatlabEngine
                            TEMPLATE = app
                            
                            DEFINES += QT_DEPRECATED_WARNINGS
                            
                            CONFIG += create_prl
                            CONFIG += link_prl
                            
                            SOURCES += main.cpp \
                                       mainwindow.cpp
                            
                            HEADERS  += mainwindow.h \
                                        engine.h
                                        matrix.h
                            
                            DISTFILES += \
                                codeMatlab.m
                            
                            LIBS += -L"C:/MATLAB/R2017b/extern/lib/win64/microsoft/" -llibeng \
                                    -L"C:/MATLAB/R2017b/extern/lib/win64/microsoft/" -llibmx
                            
                            INCLUDEPATH += C:/MATLAB/R2017b/extern/include
                            
                            

                            Thank you very for your help!!!!

                            1 Reply Last reply
                            1
                            • Z Offline
                              Z Offline
                              Zhitoune
                              wrote on last edited by
                              #14

                              I also unchecked the "shadow build" in the built settings. it started getting better after that.

                              1 Reply Last reply
                              1

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved