Exception on debug C shared library based application when using visual studio 2017
Ältere Kommentare anzeigen
Hello guys,
Now, I try and study to use Matlab library compiler to convert matlab script to library function, and call it in C application.
Follow the tutorial in help, I could manage to compile and run the matrix example with mbuild tool (matlabroot\extern\examples\compilersdk\c_cpp\matrix).
Furthermore, I want to move another step to debug the program in visual studio. I configure the visual c++ as below post.
The visual studio could compile and run the executable correctly. But, the question now is I couldn't debug it correctly.
When I use single step debug, mclInitializeApplication(NULL,0) function will run very slowly, and debug output lots of exception message.

Exception thrown at 0x00007FFE9DCA9319 in matrix_exp_svr.exe: Microsoft C++ exception: mwboost::exception_detail::clone_impl<fl::filesystem::PathNotFound> at memory location 0x00000041850F9CA0.

If I ignored those exception, and try to step over libmatrixInitialize(),

The program finally stop with the following exception.
Exception thrown at 0x000001B51C3303B4 in matrix_exp_svr.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
So, does anybody have met similar problem? Please share your insight, thanks a lot!
Jeff
5 Kommentare
Benjamin Thompson
am 1 Aug. 2022
Can you post your MATLAB code and some details on the VS 2017 version you are using?
Poorren
am 2 Aug. 2022
stomach
am 21 Apr. 2023
Hi, Poorren, did you solve this problem? I encountered the same problem that MATLAB shared library can not be debugged in visual studio.
stomach
am 21 Apr. 2023
I have found some information for this problem which says MATLAB shared library can not be built in debug mode.
Access Violation When Calling Library Function
The library file must be built in release mode, using a C++ compiler that MATLAB supports. If you build the library in debug mode, it might be incompatible with MATLAB, resulting in a termination of the program.
Antworten (3)
stomach
am 21 Apr. 2023
1 Stimme
More evidence has shown that it is impossible to debug the MATLAB shared library:
https://www.mathworks.com/matlabcentral/answers/93287-is-there-a-way-to-debug-a-matlab-compiler-4-0-r14-generated-executable
Helen
am 14 Jan. 2026
0 Stimmen
Song-Hyun Ji
am 6 Feb. 2026 um 5:30
0 Stimmen
Please see the following resource for the workaround: https://www.mathworks.com/matlabcentral/answers/1934524-how-to-supress-unhandled-exception-and-access-violation-error-messages-in-visual-studio-debugging-mo
Kategorien
Mehr zu MATLAB Compiler SDK finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

