How can i compile a source code to slcovmex format with gcc compiler?

5 ビュー (過去 30 日間)
종한 김
종한 김 2022 年 3 月 10 日
回答済み: Shubham 2024 年 1 月 15 日
Hi, i'm using gcc compiler(mingw64) to compile a source code to c-mex format.
In matlab function, there are two way to make a c-mex s-function
  1. mex (c-mex s-function)
  2. slcovmex (c-mex s-function with coverage)
i used to make c-mex s-function using gcc compiler with makefile scripts and it works properly. (not mex function in matlab)
now i want to make c-mex s-function with coverage using gcc compiler not using slcovmex function in matlab.
below is compile options and linking options i use.
CFLAGS := -w -g -fno-omit-frame-pointer -O0 -DNDEBUG -Wfatal-errors
LINKLIBS := "C:\Program Files\MATLAB\R2021b/extern/lib/win64/mingw64/libmwsl_sfcn_cov_bridge.lib" -L"$(MATLAB_ROOT_IN_MAKE)/extern/lib/win64/mingw64" -llibmx -llibmex -llibmat -lm -llibmwblas -llibmwlapack
is there any compile options i have to use when compile c-mex s-function with coverage using gcc compiler?

回答 (1 件)

Shubham
Shubham 2024 年 1 月 15 日
To compile a C-MEX S-function with coverage using GCC (MinGW64), you would typically need to add the necessary compiler flags for enabling coverage analysis. For GCC, these flags are -fprofile-arcs and -ftest-coverage. These flags tell GCC to generate additional code to record how often each line of the program is executed.
Here's how you can modify your CFLAGS and LDFLAGS to include coverage information:
CFLAGS := -w -g -fno-omit-frame-pointer -O0 -DNDEBUG -Wfatal-errors -fprofile-arcs -ftest-coverage
LDFLAGS := -fprofile-arcs -ftest-coverage
You also need to link against the coverage library libgcov. You can add it to your LINKLIBS:
LINKLIBS := "C:\Program Files\MATLAB\R2021b/extern/lib/win64/mingw64/libmwsl_sfcn_cov_bridge.lib" -L"$(MATLAB_ROOT_IN_MAKE)/extern/lib/win64/mingw64" -llibmx -llibmex -llibmat -lm -llibmwblas -llibmwlapack -lgcov
Make sure to include the LDFLAGS in the linking step of your Makefile. Here's an example of how the compilation and linking commands might look in your Makefile:
% Example compilation command
$(CC) $(CFLAGS) -c source_file.c -o source_file.o
% Example linking command
$(CC) $(LDFLAGS) source_file.o $(LINKLIBS) -o s_function.mexw64
After compiling with these options, running the generated MEX file in MATLAB will produce .gcda and .gcno files that contain the coverage data. You can then use a tool like gcov or lcov to generate a coverage report from these files.
If you want to use MATLAB's coverage tools, you will need to use MATLAB's slcovmex function or find a way to integrate MATLAB's coverage libraries and options into your build process.
Kindly refer to this documentation link: https://in.mathworks.com/help/slcoverage/ref/slcovmex.html

Community Treasure Hunt

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

Start Hunting!

Translated by