本文介绍了CMake Gcov C ++创建错误的.gcno文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中添加了CMakeLists.txt文件:

I have a CMakeLists.txt file in which I added:

set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -pthread -std=c++11 -O0 ${CMAKE_CXX_FLAGS}")

正在生成报告文件位于:

It is generating the report files in:

project_root/build/CMakeFiles/project.dir/

但是生成的文件具有扩展名 .cpp.gcno 。 cpp.gcda .cpp.o

BUT the files it generates have extentions .cpp.gcno, .cpp.gcda and .cpp.o.

此外,它们不在与src文件相同的文件夹,位于:

Also, they are not in the same folder as the src files, which are at:

project_root/src/

当我将报告文件移动到src /文件夹并执行

When I move the report files to the src/ folder and execute

$ gcov main.cpp
main.gcno:cannot open notes file

但是我收到该错误消息。所以我更改了 .cpp.gcno .cpp.cdna cpp.o .gcno .gcda .o ,最后得到以下内容:

But I get that error message. So I change the .cpp.gcno, .cpp.cdna and cpp.o to .gcno, .gcda and .o and finally I get the following:

gcov main.cpp
Lines executed:86.67% of 15
Creating 'main.cpp.gcov'

我有50多个文件,不能

I have over 50 files and can't do this manually for each one.

我需要能够对所有文件运行一次gcov并为所有文件生成报告。我不在乎文件的生成位置。

I need to be able to run gcov once for all files and generate report for all files. I don't care where the files are generated.

推荐答案

这是为项目可执行文件构建所有其他文件的目录。 / p>

This is directory where all additional files are built for 'project' executable.

这是因为CMake从<$ c $创建 .cpp.o 对象文件c> .cpp 源(您可能会看到正在运行make VERBOSE = 1 。根据 -fprofile-arcs ,数据文件后缀 .cpp.gcno

This is because CMake creates .cpp.o object file from .cpp source (you may see that running make VERBOSE=1. In accordance to -fprofile-arcs option's description, data file has suffix .cpp.gcno.

实际上,如果您调用,创建的文件仍然可以工作

Actually, created files are still work, if you call

gcov main.cpp.gcno

包含 .gcno 文件的目录。

这篇关于CMake Gcov C ++创建错误的.gcno文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:14