GCC - "has initializer but incomplete type" error when using macros for function attributes
<p>I have a few header files with some simple glorified <code>struct</code>s with just pure virtual methods defined within them. The code compiles fine on Windows with Visual Studio 2015, but GCC is getting stuck. First, the code:</p>
<h1>Code Listing</h1>
<hr />
<pre><code>namespace CustomUtils
{
    interface API_ABSTRACT overriden
    {
        virtual int GetStatus() const = 0;
    };
}
</code></pre>
<hr />
<p>In an imported header file, <code>interface</code> is just defined as a <code>stuct</code>:</p>
<pre><code>#define interface struct
</code></pre>
<p>And <code>API_ABSTRACT</code> is just a macro for nothing:</p>
<pre><code>#define API_ABSTRACT
</code></pre>
<p>The <code>interface</code> <code>typedef</code> is part of inherited code I have no control over, and the <code>API_ABSTRACT</code> is in place so that I can <a href="https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html" rel="nofollow noreferrer">define custom attributes</a> in Windows and Linux to limit which API functions I export. While this builds in VS2015, on Linux, I get a build error:</p>
<hr />
<pre><code>error: variable 'API_ABSTRACT CustomUtils::overridden' has initializer but incomplete type
</code></pre>
<hr />
<p>If I change the line:</p>
<pre><code>interface API_ABSTRACT overriden
</code></pre>
<p>To what I presume it is being translated to:</p>
<pre><code>struct overriden
</code></pre>
<p>The code will compile fine in Linux. I've tried compiling with <code>gcc -E -dD</code> to have the post-&quot;pre-processed&quot; source rendered to screen to see the <code>typedef</code> and <code>#define</code> substitutions, but it seems to only show the output for <code>.cpp</code> files, and not header (<code>.h</code>) files.</p>
<h1>The Question</h1>
<p>Why won't this code work when attempting to compile with GCC?</p>
<p>Thank you.</p>
<hr />
<h1>Edit #1</h1>
<hr />
<p>The output from <code>gcc -E</code> shows the offending line to be:</p>
<pre><code>struct API_ABSTRACT overriden
</code></pre>
<p>So it seems the culprit is the <code>API_ABSTRACT</code> macro, which evaluates to nothing.</p>