安装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 10、IDE - VS Code、编译器 - MinGw
问题:-fsanitize=address我最近发现 C++ 的清理程序可以捕获一些运行时错误,例如在我的 VS Code 环境中
进行越界数组访问-fsanitize=undefined。
当我尝试用这一行编译程序时,在 VS Code 中使用的终端是CMDg++ -fsanitize=address check.cpp -o main.exe

这是 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)
此问题的原因/解决方案 …