How can I compile a C++ program that uses MATLAB Engine C++ API in Visual Studio 2017

11 views (last 30 days)
I would like to use my IDE (Visual Studio) to compile a MATLAB Engine application that uses the MATLAB Engine for C++ API.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Aug 2019
Edited: MathWorks Support Team on 29 Aug 2019
Please refer to the following instructions:
Please note the following refer to the default MATLAB installation location.
1. Open Microsoft Visual Studio and select
File->New->Project
and then select:
Visual C++ -> General -> Empty Project
Following this, enter the name of the project and its location in the indicated text areas and click OK.
2. Right-click on the SOURCE FILES folder in the SOLUTION EXPLORER and click Add -> "New Item...". Choose "C++ file (.cpp)", enter the name of the file as xxx.cpp. Click OK.
3. Copy the source file code into the new file.
4. Right click on the project name and select PROPERTIES in the solution explorer to open the project properties. Once this window has opened, make the following changes:
a. Make sure to change the architecture to X64.
b. Under C/C++ General, add the following directory to the field ADDITIONAL INCLUDE DIRECTORIES:
C:\Program Files\MATLAB\_<ver>_\extern\include
c. Under C/C++ Precompiled Headers, select "Not Using Precompiled Headers".
d. Under Linker General, add the directory to the field ADDITIONAL LIBRARY DIRECTORIES:
C:\Program Files\MATLAB\_<ver>_\extern\lib\win64\microsoft
e. Under Configuration Properties ->Debugging
Add the following Target path to the Environment:
PATH=C:\Program Files\MATLAB\_<ver>_\extern\bin\win64;
7. Under Linker Input, add the following names to the field marked ADDITIONAL DEPENDENCIES:
libMatlabEngine.lib
libMatlabDataArray.lib
8. Make sure that the following directory is in the Windows system environment PATH:
C:\Program Files\MATLAB\_<ver>_\extern\bin\win64;
To do this, check the Windows system path by clicking on Start -> Right click on Computer -> Properties -> Advanced System Settings -> Environment variables -> System Variables -> Open "Path" for editing.
Note: If the machine has more than one MATLAB installed, the directory for the target platform must be ahead of any other MATLAB directory (for instance, when compiling a 64-bit application, the directory in the MATLAB 64-bit installation must be the first one on the PATH).
9. Build and execute the application.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!