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
Asked
Active
Viewed 2,013 times
0
-
possible duplicate of [gcov: producing .gcda output from shared library?](http://stackoverflow.com/questions/3712908/gcov-producing-gcda-output-from-shared-library) – mvp Aug 28 '13 at 08:46
-
I have gcc 4.1 toolchain, is it supported by 4.1 the link shared above reference gcc 4.5? – him Aug 28 '13 at 09:48
-
can you give details about where you compiling and where your executables are running ,i.e are you running your executable in same place where u build? – vinay hunachyal Aug 28 '13 at 09:51
-
yes, I have my executable in same place where I build and .so(used by executable) is present in same directory(as exec) [same where I build] – him Aug 28 '13 at 09:54
1 Answers
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.

vinay hunachyal
- 3,781
- 2
- 20
- 31