title: How do I resolve a "section type conflict" compile error and best practices for using section attribute with gcc
body: <p>I am using Android NDKr8 and by extension gcc to compile some library code that is shared across multiple platforms including some embedded ones.  This code uses segments to put a bunch of elements into a contiguous memory space.  The compile is generating a  "error:  variable_name causes a section type conflict".  </p>
  
  <p>We use a macro to declare the segment attribute:</p>
  
  <pre><code># define DB_SEGMENT __attribute__ ((__section__ ("DBSegment")))
  </code></pre>
  
  <p>The above variable_name is declared as follows:</p>
  
  <pre><code>dbStruct const variable_name[] DB_SEGMENT = {
      {conststringvalue0, sizeof(conststringvalue0)},
      …more like this
  };
  </code></pre>
  
  <p>dbStruct is</p>
  
  <pre><code>typedef struct dbStruct
  {
      const char * const  address;
      const UINT16        stringSize;
  } dbStruct;
  </code></pre>
  
  <p>conststringvalue0 is declared like so:</p>
  
  <pre><code>const char conststringvalue0[] DB_SEGMENT = "some string value";
  </code></pre>
  
  <p>This same code compiles in Xcode using its default compiler with only a small modification in the declaration of the DB_SEGMENT macro.  This is deeper C than I am used to so any help would be appreciated.  Google has some references to the error but the fix for it is not clear. Is there a better strategy for setting up a specific contiguous memory section?</p>
  
  <p>In response to a comment, here is the only difference fromthe correctly compiling version on XCode:</p>
  
  <pre><code>#define DB_SEGMENT __attribute__ ((section ("DBSegment,DBSection")))
  </code></pre>