使用一个单独的构建目录与CMake一起使用gcov [英] gcov with CMake using a separate build directory

查看:122
本文介绍了使用一个单独的构建目录与CMake一起使用gcov的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力获取gcov的报道信息。编译和链接期间没有错误,但是当我运行可执行文件时,不会生成coverage数据。

I'm struggling to get coverage information for gcov. No errors during compilation and linking, but when I run the executable, no coverage data is produced.

我正在使用带有单独构建目录的CMake,以这种方式将标志传递给编译器和链接器:

I'm using CMake with a separate build directory, passing flags to the compiler and linker in this way:

add_definitions(--coverage)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} " --coverage")

可执行文件是否期望源代码位于特定位置?
我必须添加到CMakeLists.txt中什么才能使事情继续进行?

Does the executable expect the source code to be in a specific location? What do I have to add to my CMakeLists.txt to get things going?

亲切的问候,
Bjoern

Kind regards, Bjoern

推荐答案

CMake似乎会将代码覆盖率(* .gcda,*。gcdo)文件与项目的目标文件一起放置。如果您的可执行文件名为 tester,则它们将出现在以下路径中

CMake seems to put the code coverage (*.gcda, *.gcdo) files with the object files of your project. If your executable was named "tester" then they would appear in the following path

${CMAKE_BINARY_DIR}/CMakeFiles/tester.dir/

CMake似乎以与gcov不太兼容的方式命名源文件。例如,如果我有一个名为 mytestprog.cpp的源文件,它将是

CMake seems to name the source files in a way that isn't very compatible with gcov though. For example if I had a source file called "mytestprog.cpp" it would be build

mytestprog.cpp.o
mytestprog.cpp.gcda
mytestprog.cpp.gcdno

其中gcov似乎在期望

where as gcov seems to expect

mytestprog.gcda
mytestprog.gcdno

我不太确定如何解决它。我尝试使用LCov代替,但似乎可以正常工作,但我不确定它是否确实有效。

I'm not really sure how to fix it. I've tried using LCov instead and that "appeared" to work but I'm not really sure if it did.

这篇关于使用一个单独的构建目录与CMake一起使用gcov的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆