title: Xcode: Type 'struct dirent' has incompatible definitions in different translation units
body: <p>I am trying to build a program with xv6's <a href="https://github.com/mit-pdos/xv6-public/blob/master/fs.h" rel="nofollow noreferrer"><code>fs.h</code></a> header file.</p>
  
  <p>I only have three files in my Xcode project: <a href="https://github.com/mit-pdos/xv6-public/blob/master/types.h" rel="nofollow noreferrer"><code>type.h</code></a>(unmodified),  <a href="https://github.com/mit-pdos/xv6-public/blob/master/fs.h" rel="nofollow noreferrer"><code>fs.h</code></a>(unmodified) and <code>main.c</code> as below.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "types.h"
  #include "fs.h"
  int main(int argc, const char * argv[]) {
      // insert code here...
      printf("Hello, World!\n");
      return 0;
  }
  </code></pre>
  
  <p>Using gcc in command line <code>gcc -o main main.c -I .</code> successfully build this program, but Xcode keeps giving me an error (Apple LLVM 9.0 Error) in <code>fs.h</code>:</p>
  
  <blockquote>
    <p>Type 'struct dirent' has incompatible definitions in different translation units</p>
  </blockquote>
  
  <p>If I replace <code>struct dirent</code> name in <code>fs.h</code> by any other names, it can build.</p>
  
  <p>How can I fix it?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>The output of running <code>gcc -o main main.c -I . -H</code>.</p>
  
  <pre><code>. /usr/include/stdio.h
  .. /usr/include/_stdio.h
  ... /usr/include/sys/cdefs.h
  .... /usr/include/sys/_symbol_aliasing.h
  .... /usr/include/sys/_posix_availability.h
  ... /usr/include/Availability.h
  .... /usr/include/AvailabilityInternal.h
  ... /usr/include/_types.h
  .... /usr/include/sys/_types.h
  ..... /usr/include/machine/_types.h
  ...... /usr/include/i386/_types.h
  ..... /usr/include/sys/_pthread/_pthread_types.h
  ... /usr/include/sys/_types/_va_list.h
  .... /usr/include/machine/types.h
  ..... /usr/include/i386/types.h
  ...... /usr/include/sys/_types/_int8_t.h
  ...... /usr/include/sys/_types/_int16_t.h
  ...... /usr/include/sys/_types/_int32_t.h
  ...... /usr/include/sys/_types/_int64_t.h
  ...... /usr/include/sys/_types/_u_int8_t.h
  ...... /usr/include/sys/_types/_u_int16_t.h
  ...... /usr/include/sys/_types/_u_int32_t.h
  ...... /usr/include/sys/_types/_u_int64_t.h
  ...... /usr/include/sys/_types/_intptr_t.h
  ....... /usr/include/machine/types.h
  ...... /usr/include/sys/_types/_uintptr_t.h
  ... /usr/include/sys/_types/_size_t.h
  ... /usr/include/sys/_types/_null.h
  ... /usr/include/sys/stdio.h
  .. /usr/include/sys/_types/_off_t.h
  .. /usr/include/sys/_types/_ssize_t.h
  .. /usr/include/secure/_stdio.h
  ... /usr/include/secure/_common.h
  . ./types.h
  . ./fs.h
  </code></pre>
  
  <p>Here is the error message from Xcode:</p>
  
  <p><a href="https://i.stack.imgur.com/f2irp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f2irp.png" alt="error"></a>
  <a href="https://i.stack.imgur.com/4yWDq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4yWDq.png" alt="error"></a></p>
  
  <p>Clicking "File has name 'd_ino' here" pops out a Xcode editor of <code>sys/dirent.h</code>. Does it mean it has conflicts with macOS system definition?</p>
  
  <p><a href="https://i.stack.imgur.com/7QiEB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7QiEB.png" alt="dirent.h"></a></p>