我正在尝试使用this guide在我正在处理的项目上运行gcov。
我按照指南上的说明阅读了很多帖子,包括本网站上的detailed guide。
但我无法使其发挥作用。
我遵循的步骤是:
我项目的主要CMakeLists.txt
位于名为cmake
的文件夹中。在此文件夹中,我创建了另一个名为CMakeModules
的文件夹,并将CodeCoverage.cmake
文件放入其中。
我将此代码添加到我的CMakeLists.txt:
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
if(CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE(NAME coverage
EXECUTABLE
DEPENDENCIES coverage)
endif()
我使用命令编译:
cmake -DCMAKE_BUILD_TYPE=DEBUG ../cmake
# (I'm compiling from a subfolder of the master folder)
make
make coverage
运行make coverage
命令时出错:
[100%] Resetting code coverage counters to zero.
Processing code coverage counters and generating report.
Errno architecture (x86_64-linux-thread-multi-4.6.4-301.fc24.x86_64) does not match executable architecture (x86_64-linux-thread-multi-4.12.9-300.fc26.x86_64) at /usr/lib64/perl5/Errno.pm line 11.
Compilation failed in require at /usr/share/perl5/vendor_perl/File/Temp.pm line 17.
BEGIN failed--compilation aborted at /usr/share/perl5/vendor_perl/File/Temp.pm line 17.
Compilation failed in require at /usr/bin/lcov line 66.
BEGIN failed--compilation aborted at /usr/bin/lcov line 66.
CMakeFiles/coverage.dir/build.make:57: set di istruzioni per l'obiettivo "CMakeFiles/coverage" non riuscito
make[3]: *** [CMakeFiles/coverage] Error 255
CMakeFiles/Makefile2:178: set di istruzioni per l'obiettivo "CMakeFiles/coverage.dir/all" non riuscito
make[2]: *** [CMakeFiles/coverage.dir/all] Errore 2
CMakeFiles/Makefile2:185: set di istruzioni per l'obiettivo "CMakeFiles/coverage.dir/rule" non riuscito
make[1]: *** [CMakeFiles/coverage.dir/rule] Errore 2
Makefile:214: set di istruzioni per l'obiettivo "coverage" non riuscito
make: *** [coverage] Errore 2
我的问题是:
究竟应该把什么放入EXECUTABLE插槽?启动程序的可执行文件的路径?
程序的设置可以通过我写的那条线来完成吗?
我已经尝试过本网站上其他线程的解决方案,但我不能告诉我如何使这项工作成功。
答案 0 :(得分:1)
EXECUTABLE
选项应定义如何在代码上运行某些内容并生成覆盖数据。
例如,它应该是运行所有测试的指令。
如果您使用ctest定义了测试,请尝试以下方法:
SETUP_TARGET_FOR_COVERAGE(NAME coverage
EXECUTABLE ctest)
(或ctest --parallel n
如果你有很多测试和多个处理器!)
如果你有一个特定的目标进行一些测试,那么尝试类似:
SETUP_TARGET_FOR_COVERAGE(NAME coverage
EXECUTABLE make target)
希望这有帮助!