相关疑难解决方法(0)

MinGW-w64的gcc和Address Sanitizer

安装MinGW-w64 5.1我找到了-fsanitize=address.编译很好,当它开始链接时,我得到成千上万:

undefined reference to '__asan_report_load1'
undefined reference to '__asan_report_load4'
Run Code Online (Sandbox Code Playgroud)

我用Google搜索并发现libasan引用了各个地方,但也评论说当你-fsanitize=address自动包含它时,它包含了用于链接的库.我搜索MinGW-w64 5.1安装目录为"asan",并没有在任何地方找到它.

在MinGW-w64中,我需要添加什么才能使用地址清理功能?谢谢.

c++ windows gcc mingw-w64 address-sanitizer

15
推荐指数
1
解决办法
3088
查看次数

无法在 minGW 编译器中使用 fsanitize=address

我的 C++ 设置信息: 操作系统 - Windows 10、IDE - VS Code、编译器 - MinGw

问题:-fsanitize=address我最近发现 C++ 的清理程序可以捕获一些运行时错误,例如在我的 VS Code 环境中 进行越界数组访问-fsanitize=undefined

这是一个用于越界数组访问的简单程序: 在此输入图像描述

当我尝试用这一行编译程序时,在 VS Code 中使用的终端是CMDg++ -fsanitize=address check.cpp -o main.exe 在此输入图像描述

按 Enter 键后出现此错误(找不到 -lasan ): 在此输入图像描述

这是 C++ 代码->

// Program to demonstrate 
// accessing array out of bounds
#include <iostream>
using namespace std ;
int main()
{
    int arr[] = {1,2,3,4,5};
    cout<<arr[0]<<endl;
      
    // arr[10] is out of bound
    cout<<arr[10]<<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

此问题的原因/解决方案 …

c++ mingw-w64 address-sanitizer visual-studio-code

8
推荐指数
0
解决办法
4771
查看次数