【VSCode】报错:出现段错误解决办法 (Segmentation fault)

VScode报错:Segmentation fault (core dumped)的解决办法

解决Program received signal SIGSEGV, Segmentation fault.的辛酸

Linux环境下段错误的产生原因及调试方法小结

Linux下的段错误Segmentationfault产生的原因及调试方法经典.pdf

在这里插入图片描述
在这里插入图片描述

在程序中,TF_SessionRun这部分总是报错Segmentation fault即出现段错误。现整理一下前后的解决过程。
首先,网上查找资料可知“段错误”一般由于访问空的指针或者堆栈溢出等。因此首先判断TF_SessionRun各参数中是否存在空指针。
使用下面这段代码可以判断指针是否为空,

 if (int_tensor != NULL) {
        printf("----------------TF_NewTensor is OK----------------\n");
    } else
        printf("ERROR: Failed TF_NewTensor\n");

    InputValues[0] = int_tensor;

    if (Input != NULL) {
        printf("----------------TF_Input is OK----------------\n");
    } else {
        printf("ERROR: Failed TF_Input\n");
    }

    if (InputValues != NULL) {
        printf("----------------TF_InputValues is OK----------------\n");
    } else {
        printf("ERROR: Failed TF_InputValues\n");
    }

    if (Output != NULL) {
        printf("----------------TF_Output is OK----------------\n");
    } else {
        printf("ERROR: Failed TF_Output\n");
    }

    if (OutputValues != NULL) {
        printf("----------------TF_OutputValues is OK----------------\n");
    } else {
        printf("ERROR: Failed TF_OutputValues\n");
    }

    if (TF_GetCode(Status) == TF_OK) {
        printf("----------------Status is OK----------------\n");
    } else {
        printf("%s", TF_Message(Status));
    }

    if (Session != NULL) {
        printf("----------------Session is OK----------------\n");
    } else {
        printf("ERROR: Failed Session\n");
    }

程序运行后显示没有问题,
【VSCode】报错:出现段错误解决办法 (Segmentation fault)_第1张图片

那么考虑第二种可能,会不会是TF_SessionRun中的某些元素初始化没有成功?通过对比两篇文章的代码,我们发现在构建inputoutput时出现了问题,因此需要加上两行代码即可:

//构建Input、Output
Input[0] = t_input;
Output[0] = t_output;

【VSCode】报错:出现段错误解决办法 (Segmentation fault)_第2张图片
解决办法:
【VSCode】报错:出现段错误解决办法 (Segmentation fault)_第3张图片

你可能感兴趣的:(vscode)