How can I compile a C++ program that uses MATLAB Engine C++ API in Visual Studio 2017
조회 수: 11 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2018년 6월 12일
편집: MathWorks Support Team
2019년 8월 29일
I would like to use my IDE (Visual Studio) to compile a MATLAB Engine application that uses the MATLAB Engine for C++ API.
채택된 답변
MathWorks Support Team
2019년 8월 29일
편집: MathWorks Support Team
2019년 8월 29일
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.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call MATLAB from C에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!