I am trying to generate coverage report for my project. the .gcno files are generated as expected for the shared object code files, but when I run the executable (which uses the shared object generated), .so is also present in same location as executable but .gcda files for shared object doesnot get generated whereas .gcda files for executable code is generated as expected. Is there something wrong in approach? PLEASE ADVISE
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Its possible to get coverage for shared libarary. i tried simple hello application profiling with gcov with shared library concept ,im able to get code coverage. let take two files hello.c and extlib.c
First compile extlib.c
#include <stdio.h>
extern void print(const char* p, ...);
void print(const char* p, ...) {
printf("%s World!\n", p);
}
gcc -shared -fPIC extlib.c -o libext.so -ftest-coverage -fprofile-arcs
here will get extlib.gcno libextlib.so
next link it to main hello program //hello.c extern void print(const char*, ...);
int main() {
print("Hello");
}
gcc hello.c -L./ -lextlib -o test -ftest-coverage -fprofile-arcs
after this hello.gcno file.
execute ./test
After execution will get extlib.gcda and hello.gcda
using gcov *.c
can check coverage.
so my suggestion try some simple file in your project individually compiling it with gcov profiling.