On 8 November 2011 12:30, Jose Fonseca <span dir="ltr">&lt;<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
At the moment MSVC build&#39;s failing with the error<br>
<br>
  mesa.lib(uniform_query.obj) : error LNK2001: unresolved external symbol &quot;int MESA_VERBOSE&quot; (?MESA_VERBOSE@@3HA)<br>
  build\windows-x86-debug\gallium\targets\libgl-gdi\opengl32.dll : fatal error LNK1120: 1 unresolved externals<br>
<br>
and trying to fix seems a to be deep rat hole. Clearly extern &quot;C&quot; is missing, but what surprises me is that this works on Linux.<br>
<br>
<br>
One problem is that putting enclose #includes inside extern &quot;C, like:<br>
<br>
<br>
  extern &quot;C&quot; {<br>
<br>
  #include &quot;foo.h&quot;<br>
<br>
  }<br>
<br>
is non portable, because &quot;foo.h&quot; may include system headers, some of which often have<br>
<br>
      #ifdef __cplusplus<br>
      // Helper C++ class<br>
      class Foo {<br>
<br>
      };<br>
      #endif /* __cplusplus */<br>
<br>
and C++ code inside extern &quot;C&quot; is an error.<br>
<br>
<br>
<br>
That is, all our .h headers that will also be included by .C++ files should follow the following pattern:<br>
<br>
<br>
  // includes (but no declarations)<br>
  #include &lt;boo.h&gt;<br>
  #include &quot;foo.h&quot;<br>
  ....<br>
<br>
<br>
  #ifdef __cplusplus<br>
  extern &quot;C&quot; {<br>
  #endif<br>
<br>
  // type/function declarations here (but no includes!)<br>
  struct aaa;<br>
  typedef int bbb;<br>
  ...<br>
<br>
  #ifdef __cplusplus<br>
  }<br>
  #endif<br>
<br>
<br>
<br>
Second, it would really help to clearly distinguish headers that are meant to be used exclusive by C++ with a different suffix (e.g., .hpp). And leave .h for headers that are meant for joint C/C++ consuption.<br>
<br>
Take e.g., ../glsl/program.h, are these supposed to be C functions or C++ functions? There&#39;s no way to tell just from reading the headers. So it&#39;s not clear if those type/functions should be inside extern &quot;C&quot;  {..} or not.<br>

<br>
<br>
Is this OK?<br>
<br>
<br>
Another approach that would avoid all these extern &quot;C&quot; would be to  all Mesa source files to .cpp. A part of a few reserver symbols and type strictness, C is a subset of C++. But this would probably be even more disruptive than adding extern &quot;C&quot; ...<br>

<br></blockquote><div><br>A (closed-source) project I worked on in the past had very good luck with a similar approach to this, however to avoid disruption in the code base, rather than change all of the .c files to .cpp, we simply changed the makefiles so that all source files were built as C++.  It might be worth a try here to ease the transition.<br>
</div></div>