问题描述
我正在为Windows和Unix编写一个跨平台C ++程序。在Window端,代码将编译并执行没有问题。在Unix端,它会编译,但是当我尝试运行它,我得到一个分段错误。
找到并修复分段错误错误的好方法是什么?
-
使用
-g
选项 -
使用命令
gdb
打开gdb控制台 -
使用命令
file
,并在控制台中传递应用程序的二进制文件。 p> -
使用命令
run
,并传递应用程序启动应用程序所需的任何参数。 -
输入您的应用程式
在 Segmantion Fault 时间中使用gdb
consolebt 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?
Compile application with
-g
option, then you have debug symbols in the binary file.Use the command
gdb
to open the gdb console.Use the command
file
and pass it your application's binary file in the console.Use the command
run
and pass it any arguments your application needs to start your application.Do something to cause your application a Segmentation Fault
Type in the
gdb
consolebt show
to get stacktrace in Segmantion Fault time.
这篇关于修复C ++中的分段故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!