@ 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 & reg; 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 (maid, '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 (MATLAB root, '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 \ MATLAB 7 \ work \ hello_test-C-zp8-G5-W3-nologo
/FOD: \ applications \ MATLAB 7 \ work \ hello_test \ hello_main.obj
-ID: \ applications \ MATLAB 7 \ extern \ include-ID: \ applications \ MATLAB 7 \ Simulink \ include
-O2-dndebug D: \ applications \ MATLAB 7 \ work \ hello_test \ hello_main.c"
--> "Cl-ID: \ applications \ MATLAB 7 \ work \ hello_test-C-zp8-G5-W3-nologo
/FOD: \ applications \ MATLAB 7 \ work \ hello_test \ hello_mcc_component_data.obj
-ID: \ applications \ MATLAB 7 \ extern \ include-ID: \ applications \ MATLAB 7 \ Simulink \ include
-O2-dndebug D: \ applications \ MATLAB 7 \ work \ hello_test \ hello_mcc_component_data.c"
--> "Link"/out: D: \ applications \ MATLAB 7 \ work \ hello_test \ hello.exe "kernel32.lib
User32.lib gdi32.lib advapi32.lib oleaut32.lib ole32.lib/libpath: "D: \ applications \ MATLAB 7 \ extern \ Lib \ Win32 \ Microsoft \ msvc71"/nologo mclmcrrt. Lib
@ D: \ applications \ MATLAB 7 \ 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 shoshould be added to your project. in this example, the following three include directories are specified.
4a1. "D: \ applications \ MATLAB 7 \ 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 \ MATLAB 7 \ extern \ include"
This directory shoshould be added to future Microsoft Visual Studio projects as an additional include directory.
4a3. "D: \ applications \ MATLAB 7 \ Simulink \ include"
This directory shocould 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 \ MATLAB 7 \ extern \ Lib \ Win32 \ Microsoft \ msvc71"
This directory shoshould 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 shoshould 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 \ MATLAB 7 \ extern \ include
-> Runtime Library: multi-threaded
5b. linker-> General (from step 4B, abve)
-> Additional library Directory: D: \ applications \ MATLAB 7 \ extern \ Lib \ Win32 \ Microsoft \ msvc71
5C. linker-> input (from Step 4c, abve)
-> additional dependencies: mclmcrrt. lib