title: LNK4217 warning on a class derived from an abstract DLL interface class
body: <p>I am getting a LNK4217 warning when compiling two classes: One is defining an abstract interface and a static factory method that will return an object that implements this interface. This class is exported via <code>__declspec(dllexport)</code>. The other class implements the interface. Here's a reduced example that reproduces the warning:</p>
  
  <p>PublicAPI.h</p>
  
  <pre><code>#pragma once
  
  #include &lt;memory&gt;
  
  #ifdef PublicAPI_Exports
  #define API_EXP __declspec (dllexport)
  #else
  #define API_EXP __declspec (dllimport)
  #endif
  
  class API_EXP PublicAPI
  {
  public:
    virtual ~PublicAPI();
  
    static std::shared_ptr&lt;PublicAPI&gt; init(const char *selection);
  
    virtual int compute() = 0;
  
  protected:
    PublicAPI();
  };
  </code></pre>
  
  <p>PublicAPI.cpp</p>
  
  <pre><code>#include "PublicAPI.h"
  #include "../PrivateAPI/PrivateAPI.h"
  
  PublicAPI::PublicAPI() {}
  
  PublicAPI::~PublicAPI() {}
  
  std::shared_ptr&lt;PublicAPI&gt; PublicAPI::init(const char *selection)
  {
    return std::make_shared&lt;PrivateAPI&gt;(selection);
  }
  </code></pre>
  
  <p>PrivateAPI.h</p>
  
  <pre><code>#pragma once
  
  #include "../PublicAPI/PublicAPI.h"
  #include &lt;memory&gt;
  #include &lt;string&gt;
  
  class PrivateAPI : public PublicAPI
  {
  public:
    PrivateAPI(std::string selection);
    virtual ~PrivateAPI();
  
    virtual int compute();
  
  private:
    PrivateAPI();
    // should have more private members here, avoided to shorten the example
  };
  </code></pre>
  
  <p>PrivateAPI.cpp</p>
  
  <pre><code>#include "PrivateAPI.h"
  
  PrivateAPI::PrivateAPI() {}
  
  PrivateAPI::PrivateAPI(std::string selection)
  {
    // init members based on selection
  }
  
  PrivateAPI::~PrivateAPI() {}
  
  int PrivateAPI::compute()
  {
    return 42;
  }
  </code></pre>
  
  <p>The <code>PrivateAPI</code> is compiled into a static lib, the <code>PublicAPI</code> into a DLL and links against <code>PrivateAPI</code>. <code>PublicAPI_Exports</code> is defined in the <code>PublicAPI</code> project.</p>
  
  <p>The warnings I am getting are:</p>
  
  <pre><code>3&gt;PrivateAPI.lib(PrivateAPI.obj) : warning LNK4217: locally defined symbol ??1PublicAPI@@UEAA@XZ (public: virtual __cdecl PublicAPI::~PublicAPI(void)) imported in function "public: virtual __cdecl PrivateAPI::~PrivateAPI(void)" (??1PrivateAPI@@UEAA@XZ)
  3&gt;PrivateAPI.lib(PrivateAPI.obj) : warning LNK4217: locally defined symbol ??0PublicAPI@@IEAA@XZ (protected: __cdecl PublicAPI::PublicAPI(void)) imported in function "private: __cdecl PrivateAPI::PrivateAPI(void)" (??0PrivateAPI@@AEAA@XZ)
  </code></pre>
  
  <p>I read through the <a href="https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4217?view=vs-2017" rel="nofollow noreferrer">Microsoft Docs</a> and StackOverflow regarding this linker warning, but I still don't get what's exactly wrong here, or how to properly fix it :/</p>