title: How to resolve the "Inconsistent dll linkage(C4273)" warning?
body: <p>I have read various "Inconsistent dll linkage" questions and answers here and none of them resolve the general problem, they are either resolving the problem for the specific code or using Visual Studio.</p>
  
  <p>I am using the cl.exe program with Visual Studio Developer prompt. I was following the walkthrough to create a dll in Visual Studio <a href="https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019" rel="nofollow noreferrer">here</a></p>
  
  <p>I have the file <code>MathLibrary.h</code> with</p>
  
  <pre><code>#pragma once
  #ifdef MATHLIBRARY_EXPORTS
  #define MATHLIBRARY_API __declspec(dllexport)
  #else
  #define MATHLIBRARY_API __declspec(dllimport)
  #endif
  extern "C" MATHLIBRARY_API void fibonacci_init(
      const unsigned long long a, const unsigned long long b);
  extern "C" MATHLIBRARY_API bool fibonacci_next();
  extern "C" MATHLIBRARY_API unsigned long long fibonacci_current();
  extern "C" MATHLIBRARY_API unsigned fibonacci_index();
  </code></pre>
  
  <p>and in the file <code>MathLibrary.cpp</code> this </p>
  
  <pre><code>#include &lt;utility&gt;
  #include &lt;limits.h&gt;
  #include "MathLibrary.h"
  static unsigned long long previous_;  
  static unsigned long long current_;
  static unsigned index_;    
  void fibonacci_init(
      const unsigned long long a,
      const unsigned long long b)
  {
      index_ = 0;
      current_ = a;
      previous_ = b; 
  }
  bool fibonacci_next()
  {
     if ((ULLONG_MAX - previous_ &lt; current_) ||
         (UINT_MAX == index_))
      {
          return false;
      }
      if (index_ &gt; 0)
      {
          // otherwise, calculate next sequence value
          previous_ += current_;
      }
      std::swap(current_, previous_);
      ++index_;
      return true;
  }
  unsigned long long fibonacci_current()
  {
      return current_;
  }
  unsigned fibonacci_index()
  {
      return index_;
  }
  </code></pre>
  
  <p>Now I use the <code>cl.exe</code> program in the Developer prompt like</p>
  
  <pre><code>cl /LD MathLibrary.cpp
  </code></pre>
  
  <p>As the file <code>MathLibrary.h</code> is in the same directory it should not create any problems. I get a bunch of "C4273" warnings. They are "Inconsistent dll linkage" warnings. </p>
  
  <p>I created a <code>MathClient.cpp</code> file with</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "MathLibrary.h"
  int main()
  {
      fibonacci_init(1, 1);
      do {
          std::cout &lt;&lt; fibonacci_index() &lt;&lt; ": "
              &lt;&lt; fibonacci_current() &lt;&lt; std::endl;
      } while (fibonacci_next());
      std::cout &lt;&lt; fibonacci_index() + 1 &lt;&lt;
          " Fibonacci sequence values fit in an " &lt;&lt;
          "unsigned 64-bit integer." &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This worked flawlessly and so I know there aren't any fatal errors, just these warnings. I have read that it is generated when MATHLIBRARY_EXPORTS is not defined and <code>__declspec(dllimport)</code> is there along with the definitions of the functions. </p>
  
  <p>I am not sure how to solve this issue as I am using the command line(Developer prompt) and I donot have the option of setting preprocessor definitions</p>