Why can't I use matlab function in QT
-
wrote on 12 Dec 2024, 13:05 last edited by
I followed the tutorial and used "Library Compiler" to transform ".m" into ".dll" ".h" and ".lib". Why does my program still fail to run?
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
-
I followed the tutorial and used "Library Compiler" to transform ".m" into ".dll" ".h" and ".lib". Why does my program still fail to run?
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
@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.
-
@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.
-
1/3