title: How to structure a C (embedded) project with shared header and code files
body: <p>This is a question of an embedded application, but I imagine the solution is language (C) based and not specific to the embedded compiler (XC16) I'm using.</p>
  <p><strong>Problem</strong></p>
  <p>I have a number of code files I am abstracting from a single project to create a shared collection of files that can be re-used across multiple projects. These files will require a config.h file in the main application to <code>#define</code> a number of parameters for that project.</p>
  <p><strong>Example</strong></p>
  <p>Files in project</p>
  <p><em>config.h</em></p>
  <pre><code>#define BUFF_SIZE 4
  </code></pre>
  <p><em>main.c</em></p>
  <pre><code>#include &quot;config.h&quot;
  #include &lt;lib.h&gt;
  /*Application Code*/
  </code></pre>
  <p>Files in 'Library' (i.e. another folder NOT in the project structure)</p>
  <p><em>lib.h</em></p>
  <pre><code>extern uint8_t Buffer [BUFF_SIZE];
  </code></pre>
  <p><em>lib.c</em></p>
  <pre><code>#include &quot;lib.h&quot;
  uint8_t Buffer [BUFF_SIZE];
  </code></pre>
  <p><strong>Question</strong></p>
  <p>This produces the issue that 'BUFF_SIZE is un-declared in lib.h'. My understanding was that the compiler would start in <em>main.c</em> load in the `#define' values from <em>config.h</em> THEN try to process the <em>lib.h</em> header. But it seems this is not the case.</p>
  <p>Do I have to back reference the library to the config.h file? This seems to work, but it then forces the application to have specific file names.</p>
  <p>Are there any good examples of how this sort of structuring should take place?</p>
  <p><strong>Additional Notes</strong></p>
  <p>The same issue arises when I try and map pin outputs for bit-bang functions. i.e.</p>
  <p><em>config.h</em></p>
  <pre><code>#define DATA_OUT LATBbits.LATB4
  </code></pre>
  <p><em>lib.c</em></p>
  <pre><code>void SetPin(void)
  {
    DATA_OUT = 1;
  }
  </code></pre>
  <p>Cheers :)</p>