'Using gcov in VSCode

I tried to use gcov through VSCode and have a problem. I configured a build task for compiling with coverage info:

{
            "type": "shell",
            "label": "Coverage build",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-Wall",
                "-Werror",
                "-Wvla",
                "-pedantic",
                "-Wextra",
                "-Wfloat-equal",
                "-ftest-coverage",
                "-fprofile-arcs",
                "-fprofile-arcs",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        }

There's no compiling errors, but .gcno and .gcda files for some reason are placed in ./MinGW/bin -- not in main file directory.

How to fix this? As that's the reason why I cannot use gcov in working directory and I do not want to open other terminal windows just to get around the problem.



Solution 1:[1]

Maybe the problem is the configuration of the working directory of the task.

Try to replace:

            "options": {
                "cwd": "C:\\MinGW\\bin"
            },

with:

            "options": {
                "cwd": "${workspaceFolder}"
            },

or something related to your Visual Studio Code project.

Solution 2:[2]

Instead of specifying -ftest-coverage and additional flags there is a --coverage flag which translates to everything needed for compilation, and it also translates to -lgcov when linking, which is is missing in your configuration and I think this is your main issue. So start using --coverage instead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 hlovdal