matlab mcl,matlab 混合编程配置

>> mex -setup

Please choose your compiler for building external interface (MEX)

files:

Would you like mex to locate installed compilers [y]/n? y

Select a compiler:

[1] Lcc-win32 C 2.4.1 in D:\PROGRA~1\MATLAB\R2008a\sys\lcc\bin

[2] Microsoft Visual C++ 6.0 in D:\Program Files\Microsoft Visual

Studio

[0] None

Compiler: 2

Please verify your choices:

Compiler: Microsoft Visual C++ 6.0

Location: D:\Program Files\Microsoft Visual Studio

Are these correct [y]/n? y

Trying to update options file: C:\Documents and

Settings\hk\Application

Data\MathWorks\MATLAB\R2008a\mexopts.bat

From

template: D:\PROGRA~1\MATLAB\R2008a\bin\win32\mexopts\msvc60opts.bat

Done . . .

3、安装MATLAB Component Runtime环境

运行MATLAB安装目录下的···\toolbox\compiler\deploy\win32\MCRInstaller.exe,开始自动安装组件运行环境。

3、使用MATLAB编译器和VC6.0实现混合编程(通过例子说明)

(1)、MATLAB中的操作

创建mccdemol.m文件,内容如下:

a4c26d1e5885305701be709a3d33442f.png

在MATLAB命令行下,将mccdemol.m编译成C++动态链接库文件。可以执行如下命令:(带图形的和不带图形的有区别,这里主要是带图形的编译)

>> mcc -W cpplib:libmccdemol -T link:lib

mccdemol.m

命令执行完成后,将在工作目录产生使用MATLAB编译生成库文件所需的相关文件。

(2)、建立VC对话框工程

创建一个基于MFC对话框的工程,工程名称为MccDemol,如下图所示:

a4c26d1e5885305701be709a3d33442f.png

设计对话框界面如图:

a4c26d1e5885305701be709a3d33442f.png

在文件MccDemolDlg.cpp

: implementation file中包含头文件,如下所示:

#include "libmccdemol.h"

修改对话框的初始函数如下:

BOOL CMccDemolDlg::OnInitDialog()

{

CDialog::OnInitDialog();

//

Add "About..." menu item to system menu.

//

IDM_ABOUTBOX must be in the system command range.

ASSERT((IDM_ABOUTBOX

& 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX

< 0xF000);

CMenu*

pSysMenu = GetSystemMenu(FALSE);

if

(pSysMenu != NULL)

{

CString

strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if

(!strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING,

IDM_ABOUTBOX, strAboutMenu);

}

}

//

Set the icon for this dialog.The

framework does this automatically

//when

the application's main window is not a dialog

SetIcon(m_hIcon,

TRUE);//

Set big icon

SetIcon(m_hIcon,

FALSE);//

Set small icon

//

TODO: Add extra initialization here

bool

res = false;

res

= mclInitializeApplication(NULL,0);

if

(!res)

{

MessageBox("初始化Application错误!");

}

res

= libmccdemolInitialize();

if

(!res)

{

MessageBox("初始化Lib错误!");

}

return

TRUE;//

return TRUEunless

you set the focus to a control

}

为对话框添加WM_DESTROY消息,使用快捷键“Ctrl+W”,调出MFC

Class Wizard对画框,如下图所示:

a4c26d1e5885305701be709a3d33442f.png

添加如下消息响应函数:

void CMccDemolDlg::OnDestroy()

{

CDialog::OnDestroy();

//

TODO: Add your message handler code here

bool

res;

res

= mclTerminateApplication();

if

(!res)

{

MessageBox("结束程序错误!");

}

libmccdemolTerminate();

}

为确定按钮添加消息响应函数

void CMccDemolDlg::OnButtonRun()

{

//

TODO: Add your control notification handler code here

mccdemol();

mclWaitForFiguresToDie(NULL);

}

本例中用到了MATLAB图形功能,所示使函数“mclWaitForFiguresToDie(NULL)”,在没有用到MATLAB的图形功能的库文件时,不需要此函数。

(3)VC中的设置

将在MATLAB环境下编译后的生成文“libmccdemol.ctf”、“libmccdemol.h”、“libmccdemol.dll”和“libmccdemol.lib”,复制到当前工程目录。

为工程添加库文件“libmccdemol.lib”和“mclmcrrt.lib”,如下图所示。

a4c26d1e5885305701be709a3d33442f.png

编译运行工程,可以看到运行结果,单击确定按钮,弹出Figure窗口。这与MATLAB环境下直接运行的结果相同。

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值