修复C ++中的分段故障 [英] Fixing Segmentation faults in C++

查看:186
本文介绍了修复C ++中的分段故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Windows和Unix编写一个跨平台C ++程序。在Window端,代码将编译并执行没有问题。在Unix端,它会编译,但是当我尝试运行它,我得到一个分段错误。



找到并修复分段错误错误的好方法是什么?

解决方案


  1. 使用 -g 选项


  2. 使用命令 gdb 打开gdb控制台


  3. 使用命令 file ,并在控制台中传递应用程序的二进制文件。 p>


  4. 使用命令 run ,并传递应用程序启动应用程序所需的任何参数。


  5. 输入您的应用程式

    Segmantion Fault 时间

    中使用 gdb console bt show


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.

What are good methodologies to find and fix segmentation fault errors?

解决方案

  1. Compile application with -g option, then you have debug symbols in the binary file.

  2. Use the command gdb to open the gdb console.

  3. Use the command file and pass it your application's binary file in the console.

  4. Use the command run and pass it any arguments your application needs to start your application.

  5. Do something to cause your application a Segmentation Fault

  6. Type in the gdb console bt show to get stacktrace in Segmantion Fault time.

这篇关于修复C ++中的分段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆