If this is a Makefile project, make sure you add -pg to the CXXFLAGS variable in the Makefile. This ensures that everything necessary for profiling (more than regular debugging symbols) is embedded in object files. You will also need to add -pg to the line where the executable will be created. Most likely, it will look like this:
$(CXX) -o $(TARGET) $(OBJS) $(LIBS)
You want to add -pg there. This will ensure that profiling information is also embedded in the executable. Now, when the program starts, the gmon.out file must be created. It will be created only if the program usually crashes.
source share