• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

HowdoIsetupaMicrosoftVisualStudioprojecttoworkwithMATLABCompiler4.0?

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
山城棒棒儿军 @ 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

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap