MATLAB not finding its own library
Show older comments
I have a C program that I am trying to compile with mex. I am able to compile the program in Visual Studio if I keep the main() function, but if I substitute in mexFunction() for main() and try to compile in MATLAB I get the following errors:
Error using mex
Creating library main_tirtos.lib and object main_tirtos.exp
Clock_HAL.obj : error LNK2019: unresolved external symbol engEvalString referenced in function
Clock_start
engine_init.obj : error LNK2001: unresolved external symbol engEvalString
RTOS_HAL.obj : error LNK2019: unresolved external symbol engOpen referenced in function BIOS_start
engine_init.obj : error LNK2001: unresolved external symbol engOpen
PIN_HAL.obj : error LNK2019: unresolved external symbol engGetVariable referenced in function
PIN_getOutputValue
engine_init.obj : error LNK2001: unresolved external symbol engGetVariable
PIN_HAL.obj : error LNK2019: unresolved external symbol engPutVariable referenced in function
PIN_setOutputValue
main_tirtos.mexw64 : fatal error LNK1120: 4 unresolved externals
It seems that MATLAB is not finding its own "engine.h" library, though I am sure I have the necessary #include as I am able to compile with Visual Studio. Any help would be appreciated!
1 Comment
Scott
on 7 Sep 2023
Answers (1)
Madheswaran
on 17 Feb 2025
0 votes
Hi Scott,
To build an engine application using MEX, you need to specify the '-client engine' flag when calling the 'mex' command. This informs MATLAB that you are building an engine application, rather than a traditional MEX file. You can find more details in the official documentation: https://mathworks.com/help/matlab/matlab_external/build-windows-engine-example.html
Without these flags, MATLAB will attempt to create a standard MEX file, which will lead to errors because your code is intended for an engine application, not a typical MEX source file.
Additionally, consider using "int main(int argc, char *argv[])" instead of "void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])" to properly define the entry point for a standalone application when working outside the MEX environment.
For more information on using MATLAB with C++, refer to the following documentation: https://mathworks.com/help/matlab/calling-matlab-engine-from-cpp-programs.html
Hope this helps!
Categories
Find more on Software Development in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!