title: Can you statically link the same protobuf message into multiple DLLs - and then have those DLLs work together?
body: <p>We are using google protobufs to pass data around on the wire.  The server side of things is plugin-like so several of the modules handling the protobuf messages are DLLs.  Some DLLs depend on others and use the others' messages to define their own messages.</p>
  
  <p>So, A.DLL has <code>a.proto</code> which generates <code>a.pb.h/cc</code> with a message class <code>MsgA</code>.  Using the undocumented <code>dllexport_decl</code> option on the protoc compiler, the message class is declared as a DLL export.</p>
  
  <p>Now, B.DLL depends on A.DLL, and <code>b.proto</code> also looks like this:</p>
  
  <pre><code>import "a.proto";
  message b 
  {
      required int32 some_number = 1;
      required PackageA.MsgA some_a = 2;
  }
  </code></pre>
  
  <p>Finally, the executable that pulls the parts together also depends on the message <code>MsgA</code>.  The protobuf library was also built as a DLL and is linked into everything.  It all builds and runs.</p>
  
  <p>But, there are <em>Forces of Light</em> which have demanded that we cut down on the DLL distribution!  So, I built the module A (which is just a collection of messages and small utils that a lot of the other plugin DLLs use) as a static library instead of a DLL.  B.DLL and the executable both link to A and everything is good - so far.  </p>
  
  <p>Since A is statically linked, <code>MsgA</code> gets fully defined in all the DLLs and the EXE.  That's OK because all the static data in the generated C++ code is const.  So what if there are multiple copies in the final process - all of the copies are identical.</p>
  
  <p>But, when I run the newly built process, libproto throws an actually useful exception - <strong>MsgA's file ID already exists in the descriptor map</strong> (or something like that).  In other words, the fact that there are multiple definitions for <code>MsgA</code> <em>is</em> a major problem.</p>
  
  <p>So, finally, here is the question(s):</p>
  
  <ul>
  <li>If we statically linked the libproto instead of using it as a DLL, would the error go away?</li>
  <li>Is it really safe to have the multiple definitions of <code>MsgA</code> scattered throughout the DLLs?</li>
  </ul>
  
  <p>The first point I can probably answer myself in a few days once I get around to rebuilding the protobuf libraries, but the second one is a little further beyond my current knowledge.  I'm also hoping to get a quick up or down answer that may save me the trouble of recompiling the proto libs.</p>