title: how to use ubsan on gcc (windows 8.1)
body: <p>In order to have a better protection against UB cases like:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int f(){
    int x;
    return x;
  }
  int main()
  {
     f();
     while(1);
     return 0;
  }
  </code></pre>
  
  <p>I've <a href="https://stackoverflow.com/a/23804850/3512538">updated</a> my GCC today so I could use <a href="https://developers.redhat.com/blog/2014/10/16/gcc-undefined-behavior-sanitizer-ubsan/" rel="nofollow noreferrer">ubsan</a>. My current version is 5.3.0  according to <code>gcc --version</code>. I thought ubsan will be added by this update, but it seems that it was not because after compiling with <code>C:\Users\my_name\Desktop&gt;gcc -fsanitize=undefined a.c</code> this is what I get:</p>
  
  <blockquote>
    <p>c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot fin
    d -lubsan</p>
  </blockquote>
  
  <p>Now, I've seen <a href="https://stackoverflow.com/questions/31803705/using-gcc-undefined-behavior-sanitizer">this post</a> but the OS is <code>Ubuntu 15.04</code> and I use <code>Win 8.1</code> so that didn't help me. One of the comments <a href="https://developers.redhat.com/blog/2014/10/16/gcc-undefined-behavior-sanitizer-ubsan/" rel="nofollow noreferrer">here</a> says: </p>
  
  <blockquote>
    <p>You will need to install the libubsan package.</p>
  </blockquote>
  
  <p>but I don't know if it was meant for <code>windows/ubuntu</code>, and even if it was for <code>windows</code> users, I don't understand how to do it.</p>
  
  <p><strong>edit:</strong> I tried also compiling <code>gcc -fno-sanitize=all a.c</code> (there are a lot of options in <a href="https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Debugging-Options.html#index-fsanitize_003dundefined-652" rel="nofollow noreferrer">here</a>) and this compiled with no warning, so I guess <code>GCC</code> recognizes the sanitizer somehow (because it compiled OK) but rejects my original compilation try for some reason</p>