Exception on debug C shared library based application when using visual studio 2017

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

Can you post your MATLAB code and some details on the VS 2017 version you are using?
Poorren
Poorren am 2 Aug. 2022
Bearbeitet: Poorren am 2 Aug. 2022
For Visual Studio, Here's the version info:
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Microsoft Visual Studio Community 2017
Version 15.9.49
VisualStudio.15.Release/15.9.49+28307.2019
Microsoft .NET Framework
Version 4.8.03761
Installed Version: Community
Visual C++ 2017 00369-60000-00001-AA404
Microsoft Visual C++ 2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%
For Matlab, it's R2021a. MATLAB Version: 9.10.0.1602886 (R2021a)
I follows the experiment step in section "Create a C Shared Library with MATLAB Code" of help system.
  1. copy example files to local folder
  2. build the library using library compiler
  3. copy the files under for_redistribution_files_only to new folder, which contains the visual studio solution.
  4. Add the library into solution/project, and set matrix.c as main entry file.
  5. build solution successfully,
  6. copy lib/dll into debug folder, then start debuging in visual studio
I attach the whole design, you could replicate after clean solution and build again.
matrix.zip contains the visual studio project, whole lib_prj.zip is compiled dll/lib.
Thanks in advance!
double check my compiler configuration
>> mex -setup
MEX configured to use 'Microsoft Visual C++ 2017 (C)' for C language compilation.
To choose a different C compiler, select one from the following:
MinGW64 Compiler (C) mex -setup:'C:\Program Files\Polyspace\R2021a\bin\win64\mexopts\mingw64.xml' C
Microsoft Visual C++ 2017 (C) mex -setup:C:\Users\userName\AppData\Roaming\MathWorks\MATLAB\R2021a\mex_C_win64.xml C
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
MEX configured to use 'Microsoft Visual C++ 2017' for C++ language compilation.
To choose a different C++ compiler, select one from the following:
MinGW64 Compiler (C++) mex -setup:'C:\Program Files\Polyspace\R2021a\bin\win64\mexopts\mingw64_g++.xml' C++
MinGW64 Compiler with Windows 10 SDK or later (C++) mex -setup:'C:\Program Files\Polyspace\R2021a\bin\win64\mexopts\mingw64_g++_sdk10+.xml' C++
Microsoft Visual C++ 2017 mex -setup:C:\Users\userName\AppData\Roaming\MathWorks\MATLAB\R2021a\mex_C++_win64.xml C++
Hi, Poorren, did you solve this problem? I encountered the same problem that MATLAB shared library can not be debugged in visual studio.
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.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

stomach
stomach am 21 Apr. 2023
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

Kategorien

Mehr zu MATLAB Compiler SDK finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021a

Gefragt:

am 1 Aug. 2022

Beantwortet:

am 6 Feb. 2026 um 5:30

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by