Here are the steps in order to compile any demo C or CPP code using Microsoft Visual C++ 2010 Express.
In this solution, we use “matcreat.cpp” as an example, which can be found at:
matlabroot\extern\examples\eng_mat
1. Create a new project
Open Microsoft Visual Studio and navigate to 'File' -> 'New' -> 'Project'.
Select ‘Visual Studio C++’ -> ' General' -> 'Empty Project'.
Name the new project as “ProjectMAT”
2 Copy the matcreat.cpp into the project folder.
Under the project “ProjetMAT”,
right-click on the 'Source Files' and 'Add' -> 'Existing Item...'.
Add the matcreat.cpp file into the project
3. Setting the Include path, library path , and linker dependencies.
Right click the “ProjectMAT” in the solution explore , choose properties -> VC++ directories
In the Include Directories: add the following
C:\Program Files (x86)\MATLAB\R2011b\extern\include;
In the Library directories : add the following
C:\Program Files (x86)\MATLAB\R2011b\extern\lib\win32\microsoft;
For 64 bit, modify the path accordingly.
In the linker ->Input, the Additional Dependencies , fill the following( here we include all the common lib files needed) , use “;” to separate each library (2010 is different from 2008!)
libmex.lib;libmat.lib;libmx.lib;libeng.lib;mclmcr.lib;
Alternately, user can also setting the include and library path through Property Manager/sheet, and this setting will apply to all the projects.
4. Setting run time library path :
Put the following string in front of your Windows PATH
C:\Program Files (x86)\MATLAB\R2011b\bin\win32;
To edit the Windows PATH, right-click My Computer, click Properties, then click Advanced System Settings, then go to the Advanced tab. Click the Environment Variables button and look for PATH (it is not case-sensitive) under System Variables. Click the Edit button and add the string above to the beginning, and save your changes.
Now you can run the compile program either under DOS or within MATLAB. Notice that a compiled 32 bit executable can only be run under 32 bit MATLAB, 64 bit executable can only be run under 64 bit MATLAB.
5. To compile a 64 executable
Open configuration manager , following the steps showing below:
Choose Configuration Manager
Choose New
Choose x64
and make sure in the Configuration Properties -> General->Platform Toolset, choose Windows 7.1SDK
The INCLUDE path and library also need to be modified accordingly:
For example, for INCLUDE path, add the following in the front:
C:\Program Files\MATLAB\R2011b\extern\include;
In the Library directories : add the following in the front
C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft
Put the following string in front of your Windows PATH
C:\Program Files\MATLAB\R2011b\bin\win64
Best Answer