MATLAB: How to compile an Engine application that uses MATLAB 7.0 (R14) in Visual Studio .NET 2003

2003buildengineMATLABnetstudiovisual

I would like to call MATLAB from my C/C++ application using the Engine interface. However, I would like to compile my project in the Microsoft Visual Studio .NET environment.

Best Answer

This change has been incorporated into the documentation in Release 2011a (R2011a). For previous releases, read below for any additional information:
The steps that are needed to compile an Engine application in Microsoft Visual Studio .NET are a combination of those in Solutions 1-OM4TI and 1-UC22O. As a complete example, see the following:
1. Open Microsoft Visual Studio .NET and select File->New->Project. Select Visual C++ Projects in the left-hand pane and Console Application (.NET) in the right-hand pane. Enter the name and path for the project and click OK.
2. Copy the code from $MATLAB\extern\examples\eng_mat\engwindemo.c, where $MATLAB is the MATLAB root directory, into myproject.cpp, where “myproject” is the name of your Visual C++ .NET project.
3. Follow the steps in Solution 1-UC22O. That is, insert the following code to your myproject.cpp source file just after the compiler directives:
struct engine
{
};
struct mxArray_tag
{
};
4. Open the project properties by right-clicking on the project name in the Solution Explorer and select Properties. Under C/C++ General, add $MATLAB\extern\include to Additional Include Directories.
5. Under C/C++ Precompiled Headers, select "Not Using Precompiled Headers".
6. Under Linker General, add $MATLAB\extern\lib\win32\microsoft\msvc71 to Additional Library Directories.
7. Under Linker Input, add libmx.lib, libmat.lib, and libeng.lib to Additional Dependencies.
8. Build the executable.