3

My issue is different than this question: the problem there was that he was compiling the same file twice.

I am only compiling each file once.

g++ -c "file_1.c" -o file_1.o  -fprofile-arcs -ftest-coverage  
g++ -c "file_2.c" -o file_2.o  -fprofile-arcs -ftest-coverage
g++ -c "file_3.c" -o file_3.o
g++ file_1.o file_2.o file_3.o -lgcov --coverage

Then when I run it, I get the error:

./a.exe
libgcov profiling error:file_1.gcda:overwriting an existing profile data with a different timestamp
libgcov profiling error:file_2.gcda:overwriting an existing profile data with a different timestamp
...

QUESTION
Why is there an error given that I only compile each instrumented file once unlike the linked question?

Bob
  • 4,576
  • 7
  • 39
  • 107
  • 1
    I cannot reproduce. Which version of GCC are you using? Could you provide a minimal example for those three files? Are three files necessary, or can it be reduced further? – amon Jul 14 '22 at 22:06
  • 1
    @amon problem was solved once I removed the artifacts from previous compilation. – Bob Jul 15 '22 at 19:04

1 Answers1

0

I had the same problem when compiling criterion in C, and found this website which explained what the origin of the error was and how to solve it. Turns out the problem was that Criterion uses file names to create its object files, and I had a file named src/str.c and a file named tests/str.c, which tested the src/str.c file.

Because those two files had the same name, even tough they were not in the same directory, Criterion encountered problems when creating object files.

You can fix this issue by changing the files' name. For example, I changed the tests/str.c into a tests/test_str.c.

If this doesn't work, you can also try removing the .gcno and .gcda files before executing the program.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
  • 4
    You've linked to a dubious scraper site that just copies content from stack overflow. The original link is https://stackoverflow.com/a/71586011/4657412 – DavidW May 07 '23 at 21:04
  • @DavidW I just periodically search for links to that site (and others) and remove them from SO. Fortunately, these websites often use url suffixes that are easily searchable and match SO posts. – General Grievance May 08 '23 at 18:42