Fixing Segmentation faults in C++(修复 C++ 中的分段错误)
问题描述
我正在为 Windows 和 Unix 编写一个跨平台的 C++ 程序.在 Window 端,代码将编译和执行没有问题.在 Unix 端,它会编译,但是当我尝试运行它时,出现分段错误.我最初的预感是指针有问题.
I am writing a cross-platform C++ program for Windows and Unix. On the Window side, the code will compile and execute no problem. On the Unix side, it will compile however when I try to run it, I get a segmentation fault. My initial hunch is that there is a problem with pointers.
找到和修复分段错误的好方法是什么?
推荐答案
使用
-g
编译您的应用程序,然后您将在二进制文件中获得调试符号.
Compile your application with
-g
, then you'll have debug symbols in the binary file.
使用 gdb
打开 gdb 控制台.
Use gdb
to open the gdb console.
使用 file
并将您的应用程序的二进制文件传递给控制台.
Use file
and pass it your application's binary file in the console.
使用 run
并传入您的应用程序启动所需的任何参数.
Use run
and pass in any arguments your application needs to start.
做一些导致分段错误的事情.
在 gdb
控制台中键入 bt
以获取分段错误的堆栈跟踪.
Type bt
in the gdb
console to get a stack trace of the Segmentation Fault.
这篇关于修复 C++ 中的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:修复 C++ 中的分段错误
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01