6

My C++ Setup INFO : OS - Windows 10, IDE - VS Code, compiler - MinGw

ISSUE : I recently found sanitizers for C++ to catch some runtime errors like out of bound array access with -fsanitize=address and -fsanitize=undefined in my VS Code environment.

This is a simple program for out of bound array access : enter image description here

in VS Code terminal being used is CMD when i tried to compile the program with this line g++ -fsanitize=address check.cpp -o main.exe enter image description here

On hitting enter I got this error ( cannot find -lasan ) : enter image description here

here is the c++ code ->

// 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;
}

Cause(s)/Solution(s) for this issue

  1. How to fix cannot find -lasan ?

  2. Does MinGW not support these sanitizers, if so, shall I use cygwin ?

  3. Can I install clang on windows machine (if possible) to use this whole bunch of sanitizers ?

  4. What are the other options to use besides using Visual Studio instead of VS Code ??

  5. Any other suggestions

NOTE : kindly suggest me suitable tags for this post (if I have used a wrong one or missed a crucial one)

humbleCodes
  • 109
  • 1
  • 6
  • 1
    Apparently not supported by mingw but should be available in clang - https://stackoverflow.com/a/55019187/4074081 – dewaffled May 20 '21 at 14:26
  • 1
    Does this answer your question? [Cannot find -lasan using address sanitizer in Qt Creator in Windows (MinGW)](https://stackoverflow.com/questions/55018627/cannot-find-lasan-using-address-sanitizer-in-qt-creator-in-windows-mingw) – dewaffled May 20 '21 at 14:28
  • @dewaffled Besides Clang any other options ?? Like Cygwin (if its an alternative to minGW) does it provide ASAN for windows ?? – humbleCodes May 21 '21 at 10:01

0 Answers0