Why do I receive an "LNK2019: unresolved external symbol _engOpen referenced in function" error when I compile my C++ code that calls the MATLAB engine API in Microsoft Visual Studio .NET?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 16 Apr 2023
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
Accepted Answer
MathWorks Support Team
on 20 Feb 2023
Edited: MathWorks Support Team
on 16 Apr 2023
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.
https://www.mathworks.com/matlabcentral/answers/96120-how-do-i-configure-my-ide-to-compile-matlab-engine-applications
0 Comments
More Answers (0)
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!