« 上一篇: Why does the PAUSE function cause my stand-alone application to hang with the MATLAB Compiler 4.0 下一篇: VC + MATLAB7 C Shared Library »
山城棒棒儿军 @ 2004-10-08 20:10

http://www.mathworks.com/support/solutions/data/1-OQHIV.html?solution=1-OQHIV

Technical Solutions
Solution Number: 1-OQHIV

Date Last Modified: 28 Sep 2004 Product:   MATLAB® Compiler
Reported in Release:   R14
Fixed in Release:    
Platform:   Windows
Operating System:   Windows Any



Subject:
How do I set up a Microsoft Visual Studio project to work with MATLAB Compiler 4.0?


Problem Description
I am using Microsoft Visual Studio with the MATLAB Compiler. How can determine which libraries and directories to include in my project?


Solution:
By looking at the verbose output generated by compiling a simple example from MATLAB, you can determine which libraries and directories to include in your project.

The following example shows how to determine the libraries and paths needed for a Microsoft Visual Studio 7.1 project by compiling the hello.m demo, which can be found in the following directory:

$MATLAB\extern\examples\compiler
(where $MATLAB = the MATLAB root directory on your machine)


1. Ensure that the Compiler has been configured using the "mbuild -setup" command.

At the MATLAB command prompt, issue the following command:


mbuild -setup



Follow the prompts to install your compiler.

2. Set up a temporary directory to compile the hello.m example, and change into that directory.

At the MATLAB command prompt, issue the following commands:


tempDir = fullfile(matlabroot,'work','hello_test');
mkdir(tempDir);
cd(tempDir);




3. Using the verbose output flag ("-v"), compile the hello.m example into the temporary directory of Step 2.

At the MATLAB command prompt, issue the following command:


mcc('-m','-v',fullfile(matlabroot,'extern','examples','compiler','hello.m'),'-d',tempDir)



You can test your compiled application by issuing the following command at the MATLAB command prompt:



system(fullfile(tempDir,'hello.exe'));



Step 4. Examine the verbose output to see what options are passed to the compiler.

Among the output generated will be the following lines:




--> "cl  -ID:\Applications\MATLAB7\work\hello_test -c -Zp8 -G5 -W3 -nologo
/FoD:\Applications\MATLAB7\work\hello_test\hello_main.obj
-ID:\Applications\MATLAB7\extern\include -ID:\Applications\MATLAB7\simulink\include
-O2 -DNDEBUG D:\Applications\MATLAB7\work\hello_test\hello_main.c"

--> "cl  -ID:\Applications\MATLAB7\work\hello_test -c -Zp8 -G5 -W3 -nologo
/FoD:\Applications\MATLAB7\work\hello_test\hello_mcc_component_data.obj
-ID:\Applications\MATLAB7\extern\include -ID:\Applications\MATLAB7\simulink\include
-O2 -DNDEBUG D:\Applications\MATLAB7\work\hello_test\hello_mcc_component_data.c"

--> "link "/out:D:\Applications\MATLAB7\work\hello_test\hello.exe" kernel32.lib
user32.lib gdi32.lib advapi32.lib oleaut32.lib ole32.lib /LIBPATH:"D:\Applications\MATLAB7\extern\lib\win32\microsoft\msvc71" /nologo mclmcrrt.lib  
@D:\Applications\MATLAB7\work\hello_test20_tmp.rsp "



4a. Look for the compiler include directories.

The include directories are contained in the lines beginning with "cl" and are denoted by "-I". The include directories that are not specific to the compiled application are the ones that should be added to your project. In this example, the following three include directories are specified.

4a1. "D:\Applications\MATLAB7\work\hello_test"

This directory does not need to be added to Microsoft Visual Studio project because the directory was specific to this application.

4a2. " D:\Applications\MATLAB7\extern\include"

This directory should be added to future Microsoft Visual Studio projects as an additional include directory.

4a3. " D:\Applications\MATLAB7\simulink\include"

This directory should not be added. The reason this include directory appears is because of a bug, as mentioned in Solution 1-O9PX9: Why do I receive a set_param Warning or Error when Using MATLAB Compiler 4.0?

http://www.mathworks.com/support/solutions/data/1-O9PX9.html

4b. Look for the linker library directories.

The linker library directories are contained in the line beginning with "link " and are denoted by "/LIBPATH:". In this example, the following linker library directory is specified.

4b1. "D:\Applications\MATLAB7\extern\lib\win32\microsoft\msvc71"

This directory should be added to future Microsoft Visual Studio projects as an additional library directory.

4c. Look for the additional MATLAB Component Runtimer (MCR) library dependency.

The MATLAB Component Runtimer (MCR) library dependency is contained in the line beginning with "link " and is denoted by "/nologo"

4c1. "mclmcrrt.lib"

This library should be added to future Microsoft Visual Studio projects as an additional dependency.


5. Add the directories and libraries of Step 4 to your Microsoft Visual Studio project.

In MSVC 7.1, set the following properties:

5a. C/C++ -> General (from Step 4a, above)

-> Additional Include directory: D:\Applications\MATLAB7\extern\include

-> Runtime library: Multi-threaded

5b. Linker -> General (from Step 4b, above)

-> Additional Library Directory: D:\Applications\MATLAB7\extern\lib\win32\microsoft\msvc71

5c. Linker -> Input (from Step 4c, above)

-> Additional dependencies: mclmcrrt.lib

最新评论 (点击这里查看更早的所有评论...)


李浩源

2004-11-06 15:07

说得也是,谢谢老大。



李浩源

2004-11-06 15:10

请问老大,1后面为什么加点,我是学汽车的,对信号处理这块不怎么熟,周围又没人感兴趣,我孤军奋战。



Genial

2004-11-06 18:55

你好,加点不是因为信号处理这一块儿的缘故,是matlab中的语法。加点表示的示矩阵的元素运算,不加点表示的是矩阵(线性代数的矩阵)运算。
我上面那样讲只是说的是一个事实,否则可能在专业方面的学习过程中会遇到更多的困难,其实都是很基础的,但是不知道的会很耗费时间。
希望继续讨论,并且,受你的影响,我也开始看一些有关DSP的了。呵呵,并且,我上周末面试了NI公司的SPE(信号处理工程师)这个职位,不过他们对口语要求挺高的,加上我不算班科出生的,可能难度比较大,等二面通知过程中ing.......



呵呵

2004-11-29 17:59

李浩源?你说话的口气很搞笑



小蜗牛

2004-12-18 14:24

各位大侠请帮我编几个最最最简单的MATLAB程序吧~~~急用!!!



小蜗牛

2004-12-18 14:35

各位大侠请帮我编几个最最最简单的MATLAB程序吧~~~急用!!!
QQ 397866175



董伟

2006-05-22 13:28

'work'什么意思啊,我也是初学,不知那个参数是干什么的,我也是学汽车的,现在在做毕业设计,请帮忙,谢谢!



董伟

2006-05-22 13:41

不好意思,我知道了,谢谢!



yyy

2006-12-17 19:52

各位:我在用VC6调用matlab7里的m程序的案例及方法做混合编程,在VC++中运行时出现了以下信息:

Linking...
  Creating library Debug/mytest.lib and object Debug/mytest.exp
mytest.obj : error LNK2001: unresolved external symbol _mylibTerminate
mytest.obj : error LNK2001: unresolved external symbol _mlfMyfun
mytest.obj : error LNK2001: unresolved external symbol _mylibInitialize
Debug/mytest.dll : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

mytest.dll - 4 error(s), 0 warning(s)
请问这是什么原因呀?



favory

2007-05-15 16:56 匿名 60.191.*.*

就是通过菜单工程/设置,打开工程设置属性页,进入Link页面,在Object/library modules编辑框中,添加文件名libmx.lib libmat.lib libeng.lib(空格分开),再将这几个lib文件从MATLAB71\extern\lib\win32\microsoft\msvc60目录中拷到当前目录中就可以啦!


评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定