MATLAB: How to integrate the C++ shared library in Visual Studio 2017

compilerdynamiclibraryMATLAB Compiler SDKsdkstaticstudiovisual

I have compiled a DLL from MATLAB and I would like to integrate it into a C++ application in Visual Studio. How can I do this?
I compiled the following MATLAB function:
function f = fact(n)
    f = prod(1:n);
end
using the following command:
mcc -B csharedlib:factlib fact.m -v
All of the files from the compilation are in "Y:\vs_example_files".

Best Answer

In all of the following instructions, replace <mcrroot> with the location the MATLAB Compiler Runtime is installed on your machine.
From your Visual Studio 2017 C++ project:
1) Open the Project > Properties menu and make sure the platform is set to "x64"
2) Under C/C++ > General, add the following directories to "Additional Include Directories"
a. The directory that "factlib.h" is in
b. <mcrroot>\extern\include
 
3) Under Linker > General, add the following directories to "Additional Library Directories"
a. The directory that "factlib.lib" is in
b. <mcrroot>\extern\lib\win64\microsoft
 
4) Under Linker > Input, add the following libraries to the list in "Additional Dependencies"
a. factlib.lib
b. mclmcrrt.lib
 
5) Save the project and close Visual Studio. Add the following directories to the Windows System Path:
a. The directory that "factlib.dll" is in
b. <mcrroot>\runtime\win64 
6) Open Visual Studio and ensure that the Solution Platform is set to "x64" from the dropdown.
7) Build and execute "vs_example.exe"