Error to call a function from C++
古いコメントを表示
I'm trying call a Matlab function from a Qt project, I have followed this tutorial to configurate Qt. So, I added the include folder path, the libeng.lib and the libmx.lib (I use the MinGW compiler). Also I defined the path to the specific dlls defined in the hierarchical tree diagram of the libeng.dll (that the Dependency Walker generated me).
My main file defines the first part of the tutorial Call MATLAB function from C++, is a example to find the greatest common divisor of two numbers using the MATLAB gcd function.
The problem is when I run the application, it crashes, and I don't know why, had anyone have a similar problem?
This is the pro file of the project:
#-------------------------------------------------
#
# Project created by QtCreator 2019-06-17T12:24:50
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Qt2Matlab
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.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
INCLUDEPATH += $$PWD/'../../../../Program Files/MATLAB/R2018a/extern/include'
LIBS += $$PWD/'../../../../Program Files/MATLAB/R2018a/extern/lib/win64/mingw64/libeng.lib' \
$$PWD/'../../../../Program Files/MATLAB/R2018a/extern/lib/win64/mingw64/libmx.lib'
LIBS += $$PWD/'../../../../Program Files/MATLAB/R2018a/bin/win64/libut.dll' \
$$PWD/'../../../../Program Files/MATLAB/R2018a/bin/win64/libmx.dll' \
$$PWD/'../../../../Windows/System32/ole32.dll' \
$$PWD/'../../../../Program Files/MATLAB/R2018a/bin/win64/vcruntime140.dll' \
$$PWD/'../../../../Windows/System32/kernel32.dll' \
$$PWD/'../../../../Program Files/MATLAB/R2018a/bin/win64/api-ms-win-crt-string-l1-1-0.dll' \
$$PWD/'../../../../Program Files/MATLAB/R2018a/bin/win64/api-ms-win-crt-runtime-l1-1-0.dll' \
$$PWD/'../../../../Program Files/MATLAB/R2018a/extern/bin/win64/libMatlabDataArray.dll' \
$$PWD/'../../../../Program Files/MATLAB/R2018a/extern/bin/win64/libMatlabEngine.dll'
And the main file:
#include "MatlabEngine.hpp"
#include "MatlabDataArray.hpp"
#include <iostream>
int main(int argc, char *argv[])
{
// Pass vector containing MATLAB data array scalar
using namespace matlab::engine;
// Start MATLAB engine synchronously
std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB();
return 0;
}
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Call MATLAB from C++ についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!