简体   繁体   English

CMake Gcov c++ 创建错误的 .gcno 文件

[英]CMake Gcov c++ creating wrong .gcno files

I have a CMakeLists.txt file in which I added:我有一个 CMakeLists.txt 文件,我在其中添加了:

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/

BUT the files it generates have extentions .cpp.gcno , .cpp.gcda and .cpp.o .但是它生成的文件有扩展名.cpp.gcno.cpp.gcda.cpp.o

Also, they are not in the same folder as the src files, which are at:此外,它们与 src 文件不在同一文件夹中,它们位于:

project_root/src/ 

When I move the report files to the src/ folder and execute当我将报告文件移动到 src/ 文件夹并执行时

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

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:所以我将.cpp.gcno.cpp.cdnacpp.o.gcno.gcda.o ,最后我得到以下内容:

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

I have over 50 files and can't do this manually for each one.我有 50 多个文件,无法为每个文件手动执行此操作。

I need to be able to run gcov once for all files and generate report for all files.我需要能够为所有文件运行一次 gcov 并为所有文件生成报告。 I don't care where the files are generated.我不在乎文件是在哪里生成的。

It is generating the report files in: project_root/build/CMakeFiles/project.dir/它正在生成报告文件:project_root/build/CMakeFiles/project.dir/

This is directory where all additional files are built for 'project' executable.这是为“项目”可执行文件构建所有附加文件的目录。

BUT the files it generates have extentions '.cpp.gcno', '.cpp.gcda' and '.cpp.o'但是它生成的文件有扩展名“.cpp.gcno”、“.cpp.gcda”和“.cpp.o”

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 .这是因为 CMake 从.cpp源创建.cpp.o目标文件(您可能会看到运行 make VERBOSE=1 。根据-fprofile-arcs 选项的描述,数据文件具有后缀.cpp.gcno

Also, they are not in the same folder as the src files此外,它们与 src 文件不在同一文件夹中

Data files are created in the same directory with object file.数据文件与目标文件在同一目录中创建。


Actually, created files are still work, if you call实际上,创建的文件仍然有效,如果你打电话

gcov main.cpp.gcno

from the directory with .gcno files.从包含.gcno文件的目录。

显然,添加扩展名以提供 .cpp.o 的标准 CMake 行为可以更改为使用以下方式替换扩展名以提供 .o :

set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM