title: C Macro - Dynamic #include
body: <p>I'm trying to figure out how to build a variable string for the #include statement using GCC.</p>
  
  <p>The idea is that for each source module I have written, I want to include as a header, a dynamically generated <strong>C</strong> source, that was created earlier in the build process.</p>
  
  <p>Generating this file is not an issue. Including it, unfortunately, is.</p>
  
  <p>What I have so far is (identities.h):</p>
  
  <pre><code>// identities.h
  
  # define PASTER2(str)  #str
  # define PASTER(str)   PASTER2(str ## .iden)
  # define EVALUATOR(x)  PASTER(x)
  
  # define IDENTITIES_FILE EVALUATOR(__FILE__)
  # include IDENTITIES_FILE
  </code></pre>
  
  <p>Ideally, this would be used like so (main.c):</p>
  
  <pre><code>//main.c
  
  # include "identities.h"
  
  int main() {return 0;}
  </code></pre>
  
  <p>Which would be expanded in a single pass by the preprocessor before compilation to yield:</p>
  
  <pre><code>//main.c (preprocessed)
  
  # include "main.c.iden"
  
  int main() {return 0;}
  </code></pre>
  
  <p>The two levels of indirection I'm using (PASTER and EVALUATOR) are a result of <a href="https://stackoverflow.com/questions/1489932/c-preprocessor-and-concatenation/1489985#1489985">this</a> post.</p>
  
  <p>Unfortunately, this is not working and I am left with the error:</p>
  
  <pre><code>obj/win32/dbg/main.o
  In file included from main.c:1:0:
  identities.h:42:1: error: #include expects "FILENAME" or &lt;FILENAME&gt;
  </code></pre>
  
  <p>I think the problem is that the include statement is missing quotes.. Any ideas?</p>