MATLAB: Do I receive an “LNK2019: unresolved external symbol _engOpen referenced in function” error when I compile the C++ code that calls the MATLAB engine API in Microsoft Visual Studio .NET

-setuplibeng.libMATLABmicrosoftmsvcstudiovisual

I have created a C++ project in Microsoft Visual Studio .NET which uses the C MATLAB engine API's. I included the engine.h file that is located in the $MATLABROOT/extern/include (where $MATLABROOT is the MATLAB root directory on my machine, as returned by typing
matlabroot
at the MATLAB command prompt.)
When I build the project I get error messages of the form: ERROR: LNK2019: unresolved external symbol _engOpen referenced in function LNK2019: unresolved external symbol _engClose referenced in function

Best Answer

This error occurs when you do not link the required static library, libeng.lib which is located in $MATLAB/extern/lib/win32/microsoft. (where $MATLAB is the MATLAB root directory on your machine, as returned by typing
matlabroot
at the MATLAB command prompt.)
In order to link the required static library, perform the following steps: (these steps may differ by Microsoft Visual Studio version)
1. Select the project in the tree and then select Project->Properties menu item to open the 'Property pages' window.
2. Here select the 'Linker' node that is under the 'Configuration Properties' node. Add the $MATLAB/extern/lib/win32/microsoft directory to the 'Additional Library Directories' field.
3. Select the 'Input' node under the 'Linker' node. Add the libeng.lib file in the 'Additional Dependencies' field.
4. Build the project.
Other modifications to your settings may also be required, for general instructions on configuring Microsoft Visual Studio, please see the related solution below.