c-从linux命令行执行时出现分段故障



我的代码在IDE中编译并运行良好。然而,当我使用gcc编译并运行a.out文件时,它会显示Segmentation fault(核心转储(。

(编辑后包含我的代码(

在main.c中,我已经注释掉了所有的代码,但它仍然会导致seg错误。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <pthread.h>

#include "BmpProcessor.h"
#include "PixelProcessor.h"
#include "PpmProcessor.h"
#include "debug.h"
#define THREAD_COUNT 8;
int main(int argc, char *argv[]) {
/** commented out all of my code */

return 0;
}

有什么想法吗?我包含的其他文件都没有主方法。

调试详细信息

gcc -g -Wall -pedantic -o PurdyImageProcessor PurdyImageProcessor.c BmpProcessor.c PpmProcessor.c PixelProcessor.c -lm -pthread
PixelProcessor.c: In function ‘boxBlurMultithreading’:
PixelProcessor.c:437:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
PixelProcessor.c: In function ‘cheesifyMultithreading’:
PixelProcessor.c:487:1: warning: control reaches end of non-void function [-Wreturn-type]
}

我们需要更多信息。请执行以下操作:

  1. 用"-g";,以获取调试信息。包括"-墙上迂腐的"对于其他编译器警告

    示例:gcc -g -Wall -pedantic -o myprog myprog.c

  2. 用你的";gcc";命令,以及您收到的编译器警告。

  3. 运行您的程序。如果它仍然崩溃,请使用gdb进行进一步分析:

    示例:CCD_ 2类型";r〃;执行。类型";bt";以便在崩溃后获取堆栈跟踪。将堆栈跟踪复制/粘贴到您的帖子中。

这里有几个有用的链接:

  • GNU调试器教程
  • 如何在程序崩溃时自动生成堆栈竞赛
  • 调试分段故障和指针问题

最新更新