c++ - Gdb。程序集生成文件中的标志 -g 不起作用

标签 c++ gdb g++

我想用 gdb 调试我的应用程序。我用 makefile 构建项目,在这里你可以看到项目构建的结果:

编译规则

%.o : %.cpp
g++ -o $@ -c $< $(COMPILE_FLAGS) $(build_flags) $(addprefix -I , $(INCLUDE_DIRS))

在哪里

build_flags := -O0 -g -DEBUG

COMPILE_FLAGS := -Wall -MD -pipe -Wno-deprecated

编译构建

mkdir -p src/. src/Object

g++ -o src/./main.o -c ../../src/./main.cpp -Wall -MD -pipe -Wno-deprecated -O0 -g -DEBUG -I ../../include

g++ -o src/Object/Object.o -c ../../src/Object/Object.cpp -Wall -MD -pipe -Wno-deprecated -O0 -g -DEBUG -I ../../include

g++ -o ../../bin/myApp_debuq src/./main.o src/Object/Object.o -s -pipe
make: Leaving directory `{project_name}/obj/debug'

我删除了不必要和冗余的信息。 在那里你可以看到很多关于构建的信息,你也可以在编译源文件时看到标志 -g 。 在那之后我想调试,然后我看到了

(gdb) file myApp_debuq

Reading symbols from {project}/bin/myApp_debuq...(no debugging symbols found)...done.

(gdb) list

No symbol table is loaded. Use the "file" command.

我怎么知道,这条消息告诉我没有调试信息。

为什么?

最佳答案

不要从可执行文件中去除调试符号!从链接命令中删除 -s

关于c++ - Gdb。程序集生成文件中的标志 -g 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9318363/

相关文章:

c++ - 在 rdbuf 之后重用 stringstream

c++ - C++ 中 undefined reference

c++ - 创建对象时出现段错误

c++ - 使用 gcc/g++ 使 C++ 程序在没有窗口的情况下运行?

c++ - C++ 中指针运算的 a+i 和 &a[i] 有什么区别?

c++ - 传递枚举数组是什么意思?

c++ - ChangeDisplaySettingsEx() 总是返回 DISP_CHANGE_BADPARAM

gdb - 在 Visual Studio Code 中使用 gdb 调试 Rust 时未命中断点

c++ - 模板化友元声明在 g++ 5.4.0 下不起作用——编译器错误或错误代码?

gcc - 强制使用 cmake 提供的最新 gcc