Matlab VC 联合编程 控制台以及MFC中实现(二)
2010-11-12 17:58
375 查看
这里首先对matlab以及vc进行配置,并介绍一下在哪里可以查到相应的帮助文档.
Matlab使用的是2010a,VC使用的是Visual Studio 2005,
Matlab Compiler安装,直接运行mbuild –setup指令,这时按照如下来运行:
实际上就是选择对应的编译器,选择好了等着安装完成就可以了.
VS2005配置,就是在工具->选项->项目和解决方案->VC++目录->包含文件中包含matlab文件夹下extern/include目录,以及库文件中包含/extern/lib/win32/microsoft目录
在写程序时需要加入matlab的一些lib文件,可以在项目属性->配置属性->链接器->输入->附加依赖项中进行设置,不过为了避免每一个项目都进行设定,这里将lib文件包含到一个头文件中,每个项目只需要包含该头文件即可.同时考虑到matlab程序可能调用matlab中的各种函数,最好是将/extern/lib/win32/microsoft目录下的所有lib文件都包含进去.这里写的matlab_header.h如下:
后面写的所有调用matlab函数的程序只需要包含该头文件即可.
Matlab中有用的帮助文档,Matlab Compiler下面的帮助很长………….这里列出一部分个人认为非常有用的,
第一个是一段视频demo,网址为http://www.mathworks.com/support/2010a/compiler/4.13/demos/using-MATLAB-Compiler.html
这段讲怎么用deploytool将一段matlab代码编译成C++的接口函数
第二个是Matlab Compiler->User Guide->Libraries->MATLAB Compiler Generated Interface Functions
这段以一个实例讲解了怎么调用接口函数,其中最重要的一段如下:
Structure of Programs That Call Shared Libraries
All programs that call MATLAB Compiler generated shared libraries have roughly the same structure:
Declare variables and process/validate input arguments.
Call mclInitializeApplication, and test for success. This function sets up the global MCR state and enables the construction of MCR instances.
Call, once for each library, <libraryname>Initialize, to create the MCR instance required by the library.
Invoke functions in the library, and process the results. (This is the main body of the program.)
Call, once for each library, <libraryname>Terminate, to destroy the associated MCR.
Call mclTerminateApplication to free resources associated with the global MCR state.
Clean up variables, close files, etc., and exit.
To see these steps in an actual example, review the main program in this example, triangle.c
.
讲解了整个程序的流程
第三个是Matlab Compiler->User Guide-> C++ Utility Library Reference
这里讲解了Matlab中的数据类型,尤其是mwArray
第四个是Matlab Compiler->Functions
主要讲解了如何调用一些函数.
第五个是Matlab->User Guide-> C/C++ and Fortran API Reference
也有一些函数可以参考
所有源程序在这里可以下到 http://download.csdn.net/source/2827645
Matlab使用的是2010a,VC使用的是Visual Studio 2005,
Matlab Compiler安装,直接运行mbuild –setup指令,这时按照如下来运行:
1 | > > mbuild - setup |
2 | |
3 | Please choose your compiler for building standalone MATLAB applications : |
4 | |
5 | Would you like mbuild to locate installed compilers [y] / n? y |
6 | |
7 | Select a compiler : |
8 | |
9 | [ 1 ] Lcc - win32 C 2 . 4 . 1 in D : /Matlab/sys/lcc |
10 | |
11 | [ 2 ] Microsoft Visual C + + 2005 SP1 in C : /Program Files/Microsoft Visual Studio 8 |
12 | |
13 | [ 0 ] None |
14 | |
15 | Compiler : 2 |
16 | |
17 | Please verify your choices : |
18 | |
19 | Compiler : Microsoft Visual C + + 2005 SP1 |
20 | |
21 | Location : C : /Program Files/Microsoft Visual Studio 8 |
22 | |
23 | Are these correct [y] / n? |
24 | |
25 | Trying to update options file : C : /Users/Administrator/AppData/Roaming/MathWorks/MATLAB/R2010a/compopts . bat |
26 | |
27 | From template : D : /Matlab/bin/win32/mbuildopts/msvc80compp . bat |
28 | |
29 | Done . . . |
30 | |
31 |
VS2005配置,就是在工具->选项->项目和解决方案->VC++目录->包含文件中包含matlab文件夹下extern/include目录,以及库文件中包含/extern/lib/win32/microsoft目录
在写程序时需要加入matlab的一些lib文件,可以在项目属性->配置属性->链接器->输入->附加依赖项中进行设置,不过为了避免每一个项目都进行设定,这里将lib文件包含到一个头文件中,每个项目只需要包含该头文件即可.同时考虑到matlab程序可能调用matlab中的各种函数,最好是将/extern/lib/win32/microsoft目录下的所有lib文件都包含进去.这里写的matlab_header.h如下:
1 | #pragma once |
2 | |
3 | #pragma comment(lib, " mclmcr.lib " ) |
4 | |
5 | #pragma comment(lib, " libmwlapack.lib " ) |
6 | |
7 | #pragma comment(lib, " mclcommain.lib " ) |
8 | |
9 | #pragma comment(lib, " libmwblascompat32.lib " ) |
10 | |
11 | #pragma comment(lib, " rtwcg.lib " ) |
12 | |
13 | #pragma comment(lib, " libut.lib " ) |
14 | |
15 | #pragma comment(lib, " libmwblas.lib " ) |
16 | |
17 | #pragma comment(lib, " physmod_foundation_util.lib " ) |
18 | |
19 | #pragma comment(lib, " libmx.lib " ) |
20 | |
21 | #pragma comment(lib, " libmex.lib " ) |
22 | |
23 | #pragma comment(lib, " ne_rtl.lib " ) |
24 | |
25 | #pragma comment(lib, " libmwsl_solver_rtw.lib " ) |
26 | |
27 | #pragma comment(lib, " libmat.lib " ) |
28 | |
29 | #pragma comment(lib, " ne_mli.lib " ) |
30 | |
31 | #pragma comment(lib, " libmwsl_fileio.lib " ) |
32 | |
33 | #pragma comment(lib, " libfixedpoint.lib " ) |
34 | |
35 | #pragma comment(lib, " mclxlmain.lib " ) |
36 | |
37 | #pragma comment(lib, " libmwservices.lib " ) |
38 | |
39 | #pragma comment(lib, " libeng.lib " ) |
40 | |
41 | #pragma comment(lib, " mclmcrrt.lib " ) |
42 | |
43 | #pragma comment(lib, " libmwmathutil.lib " ) |
44 | |
45 | #pragma comment(lib, " libemlrt.lib " ) |
46 | |
47 |
Matlab中有用的帮助文档,Matlab Compiler下面的帮助很长………….这里列出一部分个人认为非常有用的,
第一个是一段视频demo,网址为http://www.mathworks.com/support/2010a/compiler/4.13/demos/using-MATLAB-Compiler.html
这段讲怎么用deploytool将一段matlab代码编译成C++的接口函数
第二个是Matlab Compiler->User Guide->Libraries->MATLAB Compiler Generated Interface Functions
这段以一个实例讲解了怎么调用接口函数,其中最重要的一段如下:
Structure of Programs That Call Shared Libraries
All programs that call MATLAB Compiler generated shared libraries have roughly the same structure:
Declare variables and process/validate input arguments.
Call mclInitializeApplication, and test for success. This function sets up the global MCR state and enables the construction of MCR instances.
Call, once for each library, <libraryname>Initialize, to create the MCR instance required by the library.
Invoke functions in the library, and process the results. (This is the main body of the program.)
Call, once for each library, <libraryname>Terminate, to destroy the associated MCR.
Call mclTerminateApplication to free resources associated with the global MCR state.
Clean up variables, close files, etc., and exit.
To see these steps in an actual example, review the main program in this example, triangle.c
.
讲解了整个程序的流程
第三个是Matlab Compiler->User Guide-> C++ Utility Library Reference
这里讲解了Matlab中的数据类型,尤其是mwArray
第四个是Matlab Compiler->Functions
主要讲解了如何调用一些函数.
第五个是Matlab->User Guide-> C/C++ and Fortran API Reference
也有一些函数可以参考
所有源程序在这里可以下到 http://download.csdn.net/source/2827645
相关文章推荐
- Matlab VC 联合编程 控制台以及MFC中实现(四)
- Matlab VC 联合编程 控制台以及MFC中实现(三)
- Matlab VC 联合编程 控制台以及MFC中实现(五)
- Matlab VC 联合编程 控制台以及MFC中实现(一)
- 浅析VC与Matlab联合编程(三)
- VC mfc Clistbox 将里面的项目以及数据 存到txt 实现
- 浅析VC与MATLAB联合编程(四)
- VC下用MFC类实现网络编程
- VC++ MFC编程实现开机自启动
- 精通VC与Matlab联合编程(五)
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息。
- VC++MFC ADO数据库编程实现与总结
- Mathematica+Matlab联合使用实现可视化、交互编程
- 精通VC与Matlab联合编程(六)
- 浅析VC与Matlab联合编程(二)
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- VC 与MATLAB接口编程方法与实现(转)
- 精通VC与MATLAB联合编程(七)
- 精通VC与Matlab联合编程
- VC下用MFC类实现网络编程