• 6491阅读
  • 2回复

[提问]qt调用matlab生成的dll [复制链接]

上一主题 下一主题
离线林建斌
 
只看楼主 倒序阅读 楼主  发表于: 2013-05-24
我现在在做毕业设计,要做一个软件界面,里面有一个函数是用matlab语言写的,我已经可以再vs2010上调用matlab生成的dll了,但是Qt上没办法成功调用。希望大神指导下,谢谢!下面是我的代码
项目里面的代码:
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = startButton
TEMPLATE = app


SOURCES += main.cpp\
        widget.cpp

HEADERS  += widget.h \
    spot_simulationdll.h \
    libspot_simulation.h

FORMS    += widget.ui
OTHER_FILES +=
spot_simulationdll.lib
spot_simulationdll.dll
libspot_simulation.lib
libspot_simulation.dll


INCLUDEPATH += H:/matlab2011/extern/include
INCLUDEPATH += H:/matlab2011/extern/include/win32
LIBS+=-L H:/matlab2011/extern/lib/win32/microsoft -l libmx
LIBS+=-L H:/matlab2011/extern/lib/win32/microsoft -lmclmcrrt
LIBS+=-L H:/matlab2011/extern/lib/win32/microsoft -l mclmcr

cpp里面的代码:
#include "widget.h"
#include "ui_widget.h"
#include <QVBoxLayout>
#include <mclmcrrt.h>
#include <mclcppclass.h>
#include <QMessageBox>
#include <QLibrary>
#include <QMetaType>
#include <QDebug>
#include "spot_simulationdll.h"


Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    startButton =new QPushButton(tr("start"));
    connect(startButton,SIGNAL(clicked()),this,SLOT(startButtonSlots()));
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(startButton);
    setLayout(layout);

}

Widget::~Widget()
{
    delete ui;
}


typedef void (*Fun)(void); //定义函数指针,以备调用
typedef bool (*Fun2)(void);
typedef bool (*Fun3)(void);

void Widget::startButtonSlots()
{
    QLibrary lib("myfuncdll.dll");
      QMessageBox msg;
      if(lib.load())
      {
      QMessageBox::information(NULL,"OK","DLL load is OK!");
      Fun open=(Fun)lib.resolve("_spot_simulation"); //援引 _mlfMyFunc() 函数
      Fun2 init=(Fun2)lib.resolve("_spot_simulationdllInitialize");//援引 _myfuncdllInitialize() 函数
      Fun2 termi=(Fun3)lib.resolve("_spot_simulationTerminate");//援引 _myfuncdllTerminate() 函数
      if (open) //是否成功连接上 add() 函数
      {
      QMessageBox::information(NULL,"OK","Link to Function is OK!");
      init(); //库初始化
      //double _x[5] = {1, 2, 3, 4, 5}; //输入数组
     // double _y[5]; //输出数组
    //  mxArray* x = mxCreateDoubleMatrix(1, 5, mxREAL);//创建1*5矩阵
    //  memcpy(mxGetPr(x), (void*)_x, sizeof(_x)); //拷贝输入数据

    //  mxArray* y = mxCreateDoubleMatrix(1, 5, mxREAL);//创建1*5矩阵
      open();
    //  memcpy(_y, mxGetPr(y), sizeof(_y));//拷贝输出数据
    //  QString song=QString::number(_y[1]);
    //  QMessageBox::information(NULL,"OK",song);
      termi();//结束DLL库
     }
      else
      QMessageBox::information(NULL,"NO","Linke to Function is not OK!!!!");
      }
      else
      QMessageBox::information(NULL,"NO","DLL is not loaded!");




}

出现的错误
cannot find -lmclmcrrt
错误:cannot find H:/matlab2011/extern/lib/win32/microsoft: Permission denied
错误:cannot find -lmclmcr
错误:error: ld returned 1 exit status
离线dbzhang800

只看该作者 1楼 发表于: 2013-05-24
把L和l后面的空格去掉!!
离线rpdhunter

只看该作者 2楼 发表于: 2013-05-24
我也同样遇到了这个问题,迟迟得不到解决,希望看到楼主的反馈
快速回复
限100 字节
 
上一个 下一个