简体   繁体   中英

Using gcov to test a c++ program

I am using gcov for the first time to analyze my program (C++) The program consists of three classes and I have built the project using Code::Blocks. When I am invoking the program using the following command:

C:\\Users\\XXX\\Documents\\Test\\TreeObjModel\\src>gcc -fprofile-arcs -ftest-coverage Tree.cpp

I receive the following error:

Tree.cpp:1:18: fatal error: Tree.h: No such file or directory compilation terminated

While the cpp files are in the directory "C:\\Users\\XXX\\Documents\\Test\\TreeObjModel\\src\\" , the header files are in directory "C:\\Users\\XXX\\Documents\\Test\\TreeObjModel\\include\\"

Do we need to have both the code and header files in the same directory?

Thanks in advance.

You should use the -I flag to specify where your header files are.

Judging from your example, you should add -I../include

You have at least two options to instruct the compiler where to find the header files (includes).

  1. -Ipath_to_includes as parameter for gcc compiler. Eg -I../include
  2. When including in your program, specify the directory. Eg #include "../include/foo.h"

My strategy would be to just compile my project successfully and only then try to use some other stuff, like flags for code coverage. I say this because your error does not have anything to do with gcov, and trying to instrument your program to get code coverage before your program even compiles, makes things more complicated for you. One step at a time ;)

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