当我使用Qt和MATLAB混合编程时,我有一个问题。我测试了一个示例,但它失败了。这是我的代码。首先是我的职业档案:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = paintertest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
test1.cpp
HEADERS += mainwindow.h \
test1.h \
mat.h \
matrix.h \
mclbase.h \
mclcppclass.h \
mclmcr.h \
mclmcrrt.h \
tmwtypes.h \
MyAdde.h \
engine.h
FORMS += mainwindow.ui
INCLUDEPATH += D:/program/engineering/armadillo-8.200.2/include
INCLUDEPATH += D:/program/engineering/sigpack
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lblas_win32_MT
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lblas_win32_MTd
else:unix: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lblas_win32_MT
INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -llapack_win32_MT
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -llapack_win32_MTd
else:unix: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -llapack_win32_MT
INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32
unix|win32: LIBS += -L$$PWD/libBLAS_LAPACKwin32/ -lliblapacke
INCLUDEPATH += $$PWD/libBLAS_LAPACKwin32
DEPENDPATH += $$PWD/libBLAS_LAPACKwin32
INCLUDEPATH += D:/program/engineering/matlabR2014a/extern/include
INCLUDEPATH += D:/program/engineering/matlabR2014a/extern/include/win32
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibmx
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibmat
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibmex
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -lmclmcr
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -lmclmcrrt
LIBS +=-LD:/program/engineering/matlabR2014a/extern/lib/win32/microsoft -llibeng
#INCLUDEPATH += C:/Users/Administrator/Desktop/Qt/paintertest
#LIBS += -LC:/Users/Administrator/Desktop/Qt/paintertest -lMyAdde
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:unix: LIBS += -L$$PWD/./ -lMyAdde
INCLUDEPATH += $$PWD/.
DEPENDPATH += $$PWD/. 接下来是我的mainwindow.h:
#include <QMainWindow>
#include <QPainter>
#include "test1.h"
#include <QVariant>
#include <armadillo>
#include <iostream>
#include "sigpack.h"
#include "MyAdde.h"
#include "mat.h"
#include "matrix.h"
#include "mclbase.h"
#include "mclcppclass.h"
#include "mclmcr.h"
#include "mclmcrrt.h"
#include "tmwtypes.h"
#include "engine.h"接下来是我的mainwindow.cpp:
double a=6;
double b = 9;
double c;
if(MyAddeInitialize()){
qDebug()<<"ok";
}
mwArray mwA(1, 1, mxDOUBLE_CLASS);
mwArray mwB(1, 1, mxDOUBLE_CLASS);
mwArray mwC(1, 1, mxDOUBLE_CLASS);
mwA.SetData(&a, 1);
mwB.SetData(&b, 1);
MyAdde(1, mwC, mwA, mwB);
c = mwC.Get(1, 1);
cout<<"c"<<c;
MyAddeTerminate();
mclTerminateApplication();MyAdde.h/MyAdde.dll/MyAdde.lib是我的Matlab代码。下面是我的Matlab代码:
function [ c ] = MyAdde( a, b )
c = a+b;
end我使用MATLAB生成MyAdde.h/MyAdde.dll/MyAdde.lib,并将此文件添加到我的Qt pro file.But some error happened.This is my Qt error:
C:\Users\Administrator\Desktop\Qt\paintertest\mainwindow.cpp:23: error: undefined reference to `MyAdde(int, mwArray&, mwArray const&, mwArray const&)'我检查了MyAdde.h,发现了以下代码:
extern LIB_MyAdde_CPP_API void MW_CALL_CONV MyAdde(int nargout, mwArray& c, const mwArray& a, const mwArray& b);我认为这个问题是由const mwArray&和mwArray const&引起的。我不明白其中的原因。我需要你的帮助!
发布于 2017-11-08 18:20:05
这是一个链接器错误,所以它编译得很好,但链接失败
可能是这些东西错了
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./ -lMyAdde
else:unix: LIBS += -L$$PWD/./ -lMyAdde你想要达到什么目的?如果具有MyAdde dll的调试版本和发布版本,则第一行和第二行通常不应相同。
https://stackoverflow.com/questions/47148825
复制相似问题