<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi,<br>&nbsp; shown below is part of my CMakeLists.txt file<br><br>#To build the code for use with gcov, call cmake as below<br>#cmake -DGCOV=1 ..<br>IF (${GCOV})<br>&nbsp;&nbsp;&nbsp; CHECK_C_COMPILER_FLAG (<span style="font-weight: bold;">-fprofile-arcs</span> FLAG_Gcov1)<br>&nbsp;&nbsp;&nbsp; IF (FLAG_Gcov1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add_definitions (-fprofile-arcs)<br>&nbsp;&nbsp;&nbsp; ELSE (FLAG_Gcov1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MESSAGE(FATAL_ERROR "Compiler does not support the -fprofile-arcs flag needed for using gcov")<br>&nbsp;&nbsp;&nbsp; ENDIF (FLAG_Gcov1)<br>&nbsp;&nbsp;&nbsp; CHECK_C_COMPILER_FLAG (-ftest-coverage FLAG_Gcov2)<br>&nbsp;&nbsp;&nbsp; IF (FLAG_Gcov2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add_definitions (-ftest-coverage)<br>&nbsp;&nbsp;&nbsp; ELSE (FLAG_Gcov2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MESSAGE(FATAL_ERROR "Compiler
 does not support the -ftest-coverage flag needed for using gcov")<br>&nbsp;&nbsp;&nbsp; ENDIF (FLAG_Gcov2)<br>ENDIF (${GCOV})<br><br>I want to give user an option to compile the code for use with GCOV: the GNU code coverage tool. For this the code needs to be compiled with -fprofile-arcs and <br>-ftest-coverage flags.<br><br>&nbsp;&nbsp;&nbsp; When I invoke cmake as follows<br>cmake -DGCOV=1<br>I get the following error<br>CMake Error: Compiler does not support the -fprofile-arcs flag needed for using gcov<br><br>&nbsp;&nbsp;&nbsp; Well, the gcc compiler on my Linux box does support -fprofile-arcs compilation flag.<br>The CMakeFiles/CMakeError.log shows the cause of error.<br><br>=========================================================================================<br>Performing C SOURCE FILE Test FLAG_Gcov1 failed with the following output:<br>/usr/bin/gmake -f CMakeFiles/cmTryCompileExec.dir/build.make
 CMakeFiles/cmTryCompileExec.dir/build<br>gmake[1]: Entering directory `/proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp'<br>/home/srgorti/freeware/usr/bin/cmake -E cmake_progress_report /proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp/CMakeFiles 1<br>Building C object CMakeFiles/cmTryCompileExec.dir/src.o<br>/usr/local/bin/gcc&nbsp; -DFLAG_Gcov1&nbsp;&nbsp; -fprofile-arcs -o CMakeFiles/cmTryCompileExec.dir/src.o&nbsp;&nbsp; -c /proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp/src.c<br>Linking C executable cmTryCompileExec<br>/home/srgorti/freeware/usr/bin/cmake -P CMakeFiles/cmTryCompileExec.dir/cmake_clean_target.cmake<br>/usr/local/bin/gcc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -DFLAG_Gcov1&nbsp; -fPIC "CMakeFiles/cmTryCompileExec.dir/src.o"&nbsp;&nbsp; -o cmTryCompileExec -rdynamic <br>CMakeFiles/cmTryCompileExec.dir/src.o(.text+0x43): In function `global constructors keyed to 0_main':<br>: undefined reference to
 `__gcov_init'<br>CMakeFiles/cmTryCompileExec.dir/src.o(.data+0x24): undefined reference to `__gcov_merge_add'<br>collect2: ld returned 1 exit status<br>gmake[1]: *** [cmTryCompileExec] Error 1<br>gmake[1]: Leaving directory `/proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp'<br>gmake: *** [cmTryCompileExec/fast] Error 2<br><br>Source file was:<br>int main() { return 0;}<br>=========================================================================================<br><br>So the reason is when source file is compiled with -fprofile-arcs, the cmake does not<br>supply the same flag while linking which the gcc needs as the object module has certain<br>gcov related code like functions gcov_init, gcov_merge_add etc.<br><br>Is there a workaround for this? I mean since gcc does support the -fprofile-arcs<br>compilation flag, how to make cmake believe this?<br><br>Thanking you,<br>Mahendra<br><br></td></tr></table><br>