How do I build a driver application for a C++ MATLAB Data API Shared Library using Microsoft Visual Studio?

12 visualizaciones (últimos 30 días)
The easiest way to build a driver application for a C++ MATLAB Data API Shared Library is by using mbuild. The mbuild utility accepts options that relate to your filesystem (such as the location of the header files you want to include and the libraries you want to link in), and chooses the best default values for the settings you omit.
However, you may wish to use Microsoft Visual Studio on Windows to build your driver application. What are the best settings to use?

Respuesta aceptada

Alan Frankel
Alan Frankel el 16 de Jun. de 2020
Editada: Alan Frankel el 29 de Sept. de 2020
The following instructions will tell you the settings you need to build a driver application that uses a C++ MATLAB Data API Shared Library. Note that you also can run mbuild with the -v (verbose) option and save the output. You can then compare it to the output from building with Visual Studio and adjust whichever VS settings are relevant.
Microsoft Visual Studio (VS) C++ Settings For Application Using C++ MATLAB Data API Shared Library
Update Project Properties
Configuration properties
Set Configuration Manager platform to x64
C/C++
General
Additional Include Directories
<MATLAB Runtime root>\<vXY>\extern\include
<MATLAB Runtime root>\<vXY>\extern\include\win64
Language
Conformance mode: See note below
Suppress Startup Banner
Set to No in order to build in verbose mode
Linker
General
Additional Library Directories
<MATLAB Runtime root>\<vXY>\extern\lib\win64\microsoft
Input
Delay Loaded Dlls
libMatlabDataArray.dll
Add existing items to project’s Resource Files
<MATLAB Runtime root>\<vXY>\extern\lib\win64\microsoft\libMatlabCppSharedLib.lib
<MATLAB Runtime root>\<vXY>\extern\lib\win64\microsoft\libMatlabDataArray.lib
To run
Add MATLAB deployable archive (*.ctf) to folder with *.exe built by VS application
For example: <VS Solution Path>\x64\Debug
Use Debug -> Start Debugging (keyboard shortcut: F5).
If the debugger breaks when you don't want it to, adjust your exception settings by unchecking the box
next to Break when this exception type is shown in the Exception Thrown dialog. Alternatively,
use Debug -> Start Without Debugging (keyboard shortcut: Ctrl-F5).
Notes:
(1) Conformance mode: Setting Conformance mode to No will work around a compiler build issue seen in VS 2019 Community Edition with MATLAB R2018b through R2020a, in which several lines in extern\include\MatlabDataArray\ArrayFactory.hpp will trigger error C2760. (The problem has been fixed in MATLAB updates. See bug report 2149258.) Note that with mbuild, Conformance mode is set to No by default. Alternatively, particularly if Conformance mode = Yes is desired, the error can be fixed by inserting the keyword typename before instances of the strings impl::ArrayFactoryImpl and impl::ArrayImpl on those lines. The compiler error is not seen in VS 2019 Professional, VS 2017 Professional, or VS 2017 Community Edition.
(2) MatlabCppSharedLib.hpp is located in <MATLAB Runtime root>\<vXY>\extern\include
(3) libMatlabCppSharedLib.lib and libMatlabDataArray.lib are located in <MATLAB Runtime root>\<vXY>\extern\lib\win64\microsoft
(4) <MATLAB Runtime root>\<vXY> represents:
MATLAB Runtime\v91 for R2016b
MATLAB Runtime\v92 for R2017a
and so on through MATLAB Runtime\v99 for R2020b
or, for machines with MATLAB installed:
MATLAB\R2016b
MATLAB\R2017a
and so on through MATLAB\R2020b.
(5) If you have multiple versions of MATLAB or the MATLAB Runtime on your path, make sure that the first version on your Windows path does not conflict with the version from which you include header files or link libraries. If necessary, within a terminal window, set the value of PATH to only include the version of MATLAB or the MATLAB Runtime that you want to use, then start Visual Studio from the command line.
  3 comentarios
Alan Frankel
Alan Frankel el 21 de Sept. de 2022
I see it in my installation. Which version are you using, and which directory did you check?
Josue Flores de Valgas Torres
Josue Flores de Valgas Torres el 4 de Mzo. de 2023
Hi! I'm trying to process a .mat file inside a C++ code in Visual Studio 2019. I've followed every step, except for the one related to the *.ctf file, because I don't which file I'm supposed to use there. Everything else I've done it, but I get errors from the linker like the following one:
error LNK2019: unresolved external symbol mxIsDouble
Do you know what I might be doing wrong? Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre C Shared Library Integration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by