简体   繁体   中英

CMake Gcov c++ creating wrong .gcno files

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/

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

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

project_root/src/ 

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

$ 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:

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.

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.

It is generating the report files in: 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'

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 .

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

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.

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

set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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