【问题标题】:VS Code can't find malloc.cVS Code 找不到 malloc.c
【发布时间】:2018-05-31 01:21:52
【问题描述】:

当我在 C++ 中包含 cstdlib 时出现错误。

无法打开“malloc.c”:找不到文件 (file:///build/glibc-bfm8X4/glibc-2.23/malloc/malloc.c)。

错误来自 VS 代码窗口的顶部。

(调试时出错。)

以下是部分代码:

#include <cstdlib>
#include <portaudio.h>

//...

static int paCallback( const void *inputBuffer, void *outputBuffer,
                           unsigned long framesPerBuffer,
                           const PaStreamCallbackTimeInfo* timeInfo,
                           PaStreamCallbackFlags statusFlags,
                           void *userData )
{
    /* Cast data passed through stream to our structure. */
    paTestData *data = (paTestData*)userData; 
    float *out = (float*)outputBuffer;
    unsigned int i;
    (void) inputBuffer; /* Prevent unused variable warning. */

    for( i=0; i<framesPerBuffer; i++ )
    {
        *out++ = data->left_phase;  /* left */
        *out++ = data->right_phase;  /* right */

        float currentSample = 0;
        char *sampleData = new char[4];

        for(int j = 0; j < 4; j++)
        {
            sampleData[j] = currentBuffer[&currentIndex + j];
        }

        currentSample = (float)atof(sampleData); //cstdlib is included to use atof

        //gets audio sample data and forwards to PortAudio
        data->left_phase = currentSample;
        data->right_phase = currentSample;

        currentIndex += 4;
    }
    return 0;
}

如果有帮助,我正在使用 Linux Mint 81.1。

【问题讨论】:

  • 您究竟是如何包含它的?可以复制代码吗?
  • 请至少发一个minimal reproducible example
  • 请添加您正在使用的命令行和确切的错误消息。仅仅包含&lt;cstdlib&gt; 不应导致“无法打开malloc.c:...”
  • 您在内存管理代码中造成了崩溃,调试器正在寻找您造成崩溃的任何函数的源代码。没有这个文件是正常的。
  • 如果 currentBuffer 和 currentIndex 不是带有疯狂的重载运算符的对象,currentBuffer[&amp;currentIndex + j] 不应该编译。

标签: c++ linux visual-studio-code linux-mint


【解决方案1】:

我遇到了同样的问题。问题是我没有编译带有调试标志-g的cpp文件............当我重新编译包含malloc和reinterpret_cast的cpp文件时,问题就消失了。 但我错了。真正的解决方案是不要踩到 malloc 所在的行,否则需要 malloc.c 的源文件。 cf,https://github.com/microsoft/vscode-cpptools/issues/811#issuecomment-559085447

【讨论】:

    【解决方案2】:

    我已经按照以下方式解决了这个问题.. 我的错误是 “无法打开'libc-start.c':找不到文件(file:///build/glibc-OTsEL5/glibc-2.27/csu/libc-start.c” 所以我在根目录下创建了一个目录

    $cd /
    $sudo mkdir build
    $cd build
    $sudo mkdir glibc-OTsEL5
    $cd glibc-OTsEL5
    

    然后从网上下载 glibc

    $sudo wget http://ftp.gnu.org/gnu/glibc/glibc-2.27.tar.gz
    

    然后解压

    $sudo tar -xzvf glibc-2.27.tar.gz
    

    一切似乎都很好

    此解决方案取自https://github.com/microsoft/vscode-cpptools/issues/811#issuecomment-406544778

    【讨论】:

      猜你喜欢
      • 2021-05-06
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      • 2019-08-08
      • 2018-10-31
      相关资源
      最近更新 更多