Reputation: 29
I have two folder inside same folder as below :-
1.src (it contains my cpp file)
2.linux (where I am running g++ and executing o file)
now I am running commands as below
cd linux
g++ --coverage ../src/example1.cpp -o example1
./example1
cd ..
/opt/gcovr-3.2//scripts/gcovr -v -r .
I got output as, with 0% coverage
Scanning directory . for gcda/gcno files...
Found 2 files (and will process 1)
Running gcov: 'gcov /opt/gcovr-3.2/doc/examples/example1/linux/example1.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /opt/gcovr-3.2/doc/examples/example1/linux' in '/opt/gcovr-3.2/doc/examples/example1/linux'
Parsing coverage data for file /opt/gcovr-3.2/doc/examples/src/example1.cpp
Filtering coverage data for file /opt/gcovr-3.2/doc/examples/src/example1.cpp
Gathered coveraged data for 0 files
To debug further, I goto 'linux' folder as run below command
gcov /opt/gcovr-3.2/doc/examples/example1/linux/example1.gcno --branch-counts --branch-probabilities --preserve-paths --object-directory /opt/gcovr-3.2/doc/examples/example1/linux
I got output as, with valid coverage
/opt/gcovr-3.2/doc/examples/example1/linux
File '../src/example1.cpp'
Lines executed:85.71% of 7
Branches executed:100.00% of 2
Taken at least once:50.00% of 2
Calls executed:100.00% of 1
../src/example1.cpp:creating '..#src#example1.cpp.gcov'
Now I want to know what wrong I am doing? my project is complex, so I don't want to do copy all cpp files from respective 'src' folder to respective 'linux' folder. I tried with --object-directory
then also same result.
Upvotes: 3
Views: 12385
Reputation: 6018
If applicable, turn off ccache.
If ccache ever does its thing (let's say you wiped the build directory), it will happily restore the object files from cache while not restoring the *.gcno
files, because it doesn't know about those.
Upvotes: 1
Reputation: 3335
Om MacOS/Darwin with Homebrew gcc/gcovr installed, it turned out that the gcov
used by gcovr
was /usr/bin/gcov
which is the Apple/clang version which is incompatible.
I don't understand why there is no /usr/local/bin/gcov
but creating that as a link to gcov-9
solved it for me.
Upvotes: 0
Reputation: 181
gcovr uses .gcov files for analysis. I also faced similar issue and overcame it in 2 steps by manually generating .gcov file
gcov -b -l -p -c *.gcno
This will generate gcov files with all details from gcno and gcda files.gcovr -g -k -r . --html --html-details -o tp.html
or any gcovr command with -g option, -g option tells gcovr to process gcov output filesHope this solution Helps..
Upvotes: 12
Reputation: 1451
I have been working with gcovr and gcov since few months now.
The only thing that's different from what I am doing is that you are not specifying the path properly in "-r" flag.
You should specify the complete path always.
It's fine even if it's not canonical but path should be complete.
And always specify an extra slash "/" or "\" for linux and windows respectively after the root directory name. For example
-r "/path/to/root/directory/"
It seems that this extra slash is important otherwise it gives problem. Don't know the exact problem, but I assumed it doesn't search recursively without the end slash.
Upvotes: 1