I am trying to run profile guided optimization on my code with -fprofile-generate
flag. When I compile with it, I am getting the following error.
obj\Debug\main.o||In function ZNSt10_HashtableIiSt4pairIKiiESaIS2_ENSt8__detail10_Select1stESt8equal_toIiESt4hashIiENS4_18_Mod_range_hashingENS4_20_Default_ranged_hashENS4_20_Prime_rehash_policyENS4_17_Hashtable_traitsILb0ELb0ELb1EEEE5clearEv':|
c:\program files (x86)\gfortran\lib\gcc\mingw32\4.10.0\include\c++\bits\hashtable.h|1937|undefined reference to __gcov_indirect_call_profiler_v2'|
c:\program files (x86)\gfortran\lib\gcc\mingw32\4.10.0\include\c++\bits\hashtable.h|1937|undefined reference to __gcov_indirect_call_callee'|
c:\program files (x86)\gfortran\lib\gcc\mingw32\4.10.0\include\c++\bits\hashtable.h|1937|undefined reference to __gcov_time_profiler'|
c:\program files (x86)\gfortran\lib\gcc\mingw32\4.10.0\include\c++\bits\hashtable.h|1942|undefined reference to __gcov_one_value_profiler'|
c:\program files (x86)\gfortran\lib\gcc\mingw32\4.10.0\include\c++\bits\hashtable.h|1942|undefined reference to __gcov_average_profiler'|
c:\program files (x86)\gfortran\lib\gcc\mingw32\4.10.0\include\c++\bits\hashtable.h|1942|undefined reference to __gcov_ior_profiler'|
There are other error messages in the but all of them are related to __gcov
I am not able to find anything online regarding this. Can someone please help?
I am using g++ 8.1.0 on windows and using -march=native
, -std=c++14
and -ffast-math
flags. The program complies and runs perfectly fine without -fprofile-generate
flag.
Try the edit on the end of this question of mine for a possibility: How can i get gcc profile guided optimizations to stop writing files after being 'optimized'?
edit: nvm, i tried to remove the flag and it crashes at runtime instead of compile time. I don't understand how this is supposed to not write files.
edit2: I found the cause in my case, which might be the same as yours.
The makefile 'make clean' wasn't cleaning all .o files from the dir, so between the profile-sampling build (which does use gcov in the LDFlags, or more exactly, fprofile-generate pulls it in), and the profile-optimization build there were left-over .o files the linker tries to pull in because the source 'didn't change', files with the wrong dependency.
Make sure your .o and .d files are deleted before the second optimization build.