解决 Dev C++ 无法调试的问题

前言

在考场上常见的3个 C/C++ IDE:Visual C++ 6.0,Code::Blocks中,Dev C++ 可以单文件调试,无须建立工程,较为方便,但是每次上考场,都会遇到无法调试的问题,参考两篇博文1,百度经验2 后发现,只需要改动一个参数即可。

增加 -g3 参数

在 GUI 中只需要点击 Tools->Compiler Options... -> Settings -> Linker ,将 Generate debugging information (-g3) 的值修改为 Yes即可,如下图:

解决 Dev C++ 无法调试的问题

其中,参数 -g3GCC官方文档第109页这样解释道:

-gvmslevel
Request debugging information and also use level to specify how much information.
The default level is 2.
Level 0 produces no debug information at all. Thus, ‘-g0’ negates ‘-g’.
Level 1 produces minimal information, enough for making backtraces in parts
of the program that you don’t plan to debug. This includes descriptions of
functions and external variables, and line number tables, but no information
about local variables.
Level 3 includes extra information, such as all the macro definitions present in
the program. Some debuggers support macro expansion when you use ‘-g3’.
‘-gdwarf’ does not accept a concatenated debug level, to avoid confusion with
‘-gdwarf-level’. Instead use an additional ‘-glevel’ option to change the
debug level for DWARF.

注意

源码文件名一定要是英文名,使用中文会无法调试。如 邻接表.cpp 不能调试, adjacency_list.cpp 可以。