Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why can't I use matlab function in QT
Forum Updated to NodeBB v4.3 + New Features

Why can't I use matlab function in QT

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 161 Views
  • 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.
  • R Offline
    R Offline
    Ray_Zh
    wrote on 12 Dec 2024, 13:05 last edited by
    #1

    I followed the tutorial and used "Library Compiler" to transform ".m" into ".dll" ".h" and ".lib". Why does my program still fail to run?
    屏幕截图 2024-12-12 210501.png

    Here is my ".pro"

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++17
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        main.cpp \
        mainwindow.cpp
    
    HEADERS += \
        mainwindow.h \
        mat/add_matlab.h
    
    FORMS += \
        mainwindow.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./release/ -ladd_matlab
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./debug/ -ladd_matlab
    
    INCLUDEPATH += $$PWD/mat
    DEPENDPATH += $$PWD/mat
    
    INCLUDEPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/include)
    INCLUDEPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/include/win64)
    
    INCLUDEPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft)
    DEPENDPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft)
    
    win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibmex
    win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibmx
    win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibmat
    win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibeng
    win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -lmclmcr
    win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -lmclmcrrt
    
    J 1 Reply Last reply 12 Dec 2024, 13:33
    0
    • R Ray_Zh
      12 Dec 2024, 13:05

      I followed the tutorial and used "Library Compiler" to transform ".m" into ".dll" ".h" and ".lib". Why does my program still fail to run?
      屏幕截图 2024-12-12 210501.png

      Here is my ".pro"

      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      CONFIG += c++17
      
      # You can make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      SOURCES += \
          main.cpp \
          mainwindow.cpp
      
      HEADERS += \
          mainwindow.h \
          mat/add_matlab.h
      
      FORMS += \
          mainwindow.ui
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./release/ -ladd_matlab
      else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./debug/ -ladd_matlab
      
      INCLUDEPATH += $$PWD/mat
      DEPENDPATH += $$PWD/mat
      
      INCLUDEPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/include)
      INCLUDEPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/include/win64)
      
      INCLUDEPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft)
      DEPENDPATH += $$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft)
      
      win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibmex
      win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibmx
      win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibmat
      win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -llibeng
      win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -lmclmcr
      win32: LIBS += -L$$quote(D:/Program Files/MATLAB/R2024a/extern/lib/win64/microsoft) -lmclmcrrt
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 12 Dec 2024, 13:33 last edited by
      #2

      @Ray_Zh said in Why can't I use matlab function in QT:

      Why does my program still fail to run?

      It fails to link, not to run. Linker fails because it can't find matlab lib. It can't find the lib probably because you used $$PWD in:

      LIBS += -L$$PWD/./release/ -ladd_matlab
      

      PWD is current folder when running qmake. Where did you put the matlab libraries? Please post the resulting path from the -L when linker is executed: is that path correct and is the lib in that folder?

      Please post error messages as text.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 13 Dec 2024, 01:39
      1
      • J jsulm
        12 Dec 2024, 13:33

        @Ray_Zh said in Why can't I use matlab function in QT:

        Why does my program still fail to run?

        It fails to link, not to run. Linker fails because it can't find matlab lib. It can't find the lib probably because you used $$PWD in:

        LIBS += -L$$PWD/./release/ -ladd_matlab
        

        PWD is current folder when running qmake. Where did you put the matlab libraries? Please post the resulting path from the -L when linker is executed: is that path correct and is the lib in that folder?

        Please post error messages as text.

        R Offline
        R Offline
        Ray_Zh
        wrote on 13 Dec 2024, 01:39 last edited by
        #3

        @jsulm Thanks。 That's the problem. I never doubted this line because it was automatically generated by the program when I imported the library

        1 Reply Last reply
        0
        • R Ray_Zh has marked this topic as solved on 13 Dec 2024, 01:41

        1/3

        12 Dec 2024, 13:05

        • Login

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