Reputation: 332
Im getting the following errors during compilation and linking while using gcov to get coverage information
error: undefined reference to '__gcov_merge_add'
error: undefined reference to '__gcov_init'
Im passing flags to the CMakeLists.txt like this:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
Do I have to add any thing else to the CMakeLists.txt?
Upvotes: 4
Views: 4327
Reputation: 2480
Set the compiler flags
add_compile_options(-g -O0 -fprofile-arcs -ftest-coverage)
Link to lgcov
target_link_libraries(
<target-name>
gcov
)
Or use a CMake module
Upvotes: 5
Reputation: 78330
Assuming you only want coverage for Debug builds, your flags should be:
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
For further info, see http://cmake.org/Wiki/CTest/Coverage and http://cmake.org/Wiki/CTest/Coverage/Example
Upvotes: 0