title: Error C2491: definition of dllimport function not allowed
body: <p>I have a problem with make a dll on Visual Studio 2013. This code works on Code::Blocks. The error was <code>definition of dllimport function not allowed" on line void DLL_EXPORT prim(map&lt;string, vector&lt;int&gt;&gt; nodes, map&lt;pair&lt;string, string&gt;, pair&lt;int, string&gt;&gt; edges)</code>. How to fix it?</p>
  
  <pre><code>main.h:
  #ifndef __MAIN_H__
  #define __MAIN_H__
  
  #include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;map&gt;
  
  using namespace std;
  
  #ifdef BUILD_DLL
      #define DLL_EXPORT __declspec(dllexport)
  #else
      #define DLL_EXPORT __declspec(dllimport)
  #endif
  
  
  #ifdef __cplusplus
  extern "C"
  {
  #endif
  
  void DLL_EXPORT prim( map&lt;string,vector&lt;int&gt;&gt; nodes, map&lt;pair&lt;string,string&gt;,pair&lt;int,string&gt;&gt; edges);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif // __MAIN_H__
  </code></pre>
  
  <p>And the second file:</p>
  
  <pre><code>main.cpp:
  #include "main.h"
  //some other includes
  
  // a sample exported function
  
  extern "C"
  {
      void DLL_EXPORT prim(map&lt;string, vector&lt;int&gt;&gt; nodes, map&lt;pair&lt;string, string&gt;, pair&lt;int, string&gt;&gt; edges)
      {
          //some code
      }
  }
  </code></pre>
  
  <p>I tried to fix it, but I have no more idea. When I changed the prim function in second file from definition to the declaration, the dll was compile without errors, but without the code responsible for the implementation of the algorithm.</p>
  
  <p>Thanks for all replies.</p>
  
  <p>Edit:</p>
  
  <p>I add temporary #define BUILD_DLL to main.h and later in Cmake and I works. Thanks for replies.</p>