question
I used a makefile to compile a release version of the executable file before, but when I wanted to debug it later, I found that it couldn't be debugged.
I thought -g
it would solve the problem, but later I found out that it didn't work at all.
Although options have been added here -g
, the source file still cannot be found during debugging.
solution
How to convert the release version of an existing C/C++ project compiled with a makefile into a debug version without changing the source code.
After carefully studying the makefile on this issue, I realized that the rules of the makefile are based on the timestamp.
In other words, if the source code does not change, .o
the intermediate files generated by the original release version can be debugged even if options are added to the makefile later -g
, but they cannot be entered into the source code. Because the source file has not changed, .o
the intermediate file will not be regenerated, and the corresponding -g
options will not be added.
Final operation:
On the one hand: add compilation options in the makefile; -g
on the other hand:.o
It is very important to delete all intermediate files generated by the originally compiled release version .
There is also something mentioned in the book before: -g
options and code optimization options -O/O1/O2/O3
should not appear at the same time.