title: Why am I getting "undefined reference to `_stat`" in the sys/stat.h library?
body: <p>I'm trying to use the <code>stat()</code> function in the `#include &lt;sys/stat.h&gt; library however whenever I call it I get this error:</p>
  <pre><code>...toolchains/gcc-arm-none-eabi-8-2018/arm-gcc-macos/arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(lib_a-statr.o): in function `_stat_r':
  statr.c:(.text._stat_r+0xe): undefined reference to `_stat'
  </code></pre>
  <p>Here is my file (I've listed all my includes, I know some might be not related to this problem but just incase I've listed all):</p>
  <pre><code>#include &lt;kernel.h&gt;
  #include &lt;device.h&gt;
  #include &lt;drivers/i2c.h&gt;
  #include &lt;sys/__assert.h&gt;
  #include &lt;logging/log.h&gt;
  #include &lt;sys/printk.h&gt;
  #include &lt;soc.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;string.h&gt;
  
  #define SOURCE_FILE   &quot;battery.gm.fs&quot;
  
  int write_to_dev(struct device* dev)
  {
      struct stat st;
      int nSourceFile;
      char *pFileBuffer;
  
      stat(SOURCE_FILE, &amp;st); // problematic line
      // other code here
  }
  </code></pre>
  <p>Whenever I call <code>write_to_dev()</code> I'm getting this issue. I'm basing my code off page 17 of this link: <a href="https://www.ti.com/lit/an/slua801/slua801.pdf?ts=1595360845070&amp;ref_url=https%253A%252F%252Fwww.google.com%252F" rel="nofollow noreferrer">https://www.ti.com/lit/an/slua801/slua801.pdf?ts=1595360845070&amp;ref_url=https%253A%252F%252Fwww.google.com%252F</a> Thanks for your help!</p>
  <p>Edit: I'm using an STM32 chip with zephyr RTOS, and TI BQ27621 fuel gauge</p>