title: Error C2491: Function declared in header and defined in C++
body: <p>I have been trying to build a device adapter for a open-source software called Micro-manager to control a microscope and there are some problems that I am facing, there are these two files (one header and the other CPP) that are already present in the open source package of Micro-Manager.</p>
  
  <pre><code>//MoudluleInterface.h
  
  #ifndef _MODULE_INTERFACE_H_
  #define _MODULE_INTERFACE_H_
  
  #ifdef WIN32
  #ifdef MODULE_EXPORTS
    #define MODULE_API __declspec(dllexport)
  #else
    #define MODULE_API __declspec(dllimport)
  #endif
  
  #else
  #define MODULE_API
  #endif
  #define MM_MODULE_ERR_OK 1000
  #define MM_MODULE_ERR_WRONG_INDEX   1001
  #define MM_MODULE_ERR_BUFFER_TOO_SMALL 1002
  
   ///////////////////////////////////////////////////////////////////////////////
   // header version
   // NOTE: If any of the exported module API calls changes, the interface version
   // must be incremented
   // new version 5 supports device discoverability
   #define MODULE_INTERFACE_VERSION 7
  
  #ifdef WIN32
  const char* const LIB_NAME_PREFIX = "mmgr_dal_";
  #else
  const char* const LIB_NAME_PREFIX = "libmmgr_dal_";
  #endif
  
  #include "MMDevice.h"
  
  ///////////////////////////////////////////////////////////////////////////////
  // Exported module interface
  ///////////////////////////////////////////////////////////////////////////////
   extern "C" {
   MODULE_API MM::Device* CreateDevice(const char* name);
   MODULE_API void DeleteDevice(MM::Device* pDevice);
   MODULE_API long GetModuleVersion();
   MODULE_API long GetDeviceInterfaceVersion();
   MODULE_API unsigned GetNumberOfDevices();
   MODULE_API bool GetDeviceName(unsigned deviceIndex, char* name, unsigned      bufferLength);
   MODULE_API bool GetDeviceDescription(const char* deviceName, char* name, unsigned bufferLength);
  </code></pre>
  
  <p>And here is a part of the CPP file which defines these functions</p>
  
  <pre><code>      //ModuleInterface.cpp
        #define _CRT_SECURE_NO_DEPRECATE
        #include "ModuleInterface.h"
        #include &lt;vector&gt;
        #include &lt;string&gt;
  
          typedef std::pair&lt;std::string, std::string&gt; DeviceInfo; 
          std::vector&lt;DeviceInfo&gt; g_availableDevices;
  
        int FindDeviceIndex(const char* deviceName)
     {
    for (unsigned i=0; i&lt;g_availableDevices.size(); i++)
    if (g_availableDevices[i].first.compare(deviceName) == 0)
       return i;
  
     return -1;
     }
  
    MODULE_API long GetModuleVersion()
   {
   return MODULE_INTERFACE_VERSION;   
   }
  
    MODULE_API long GetDeviceInterfaceVersion()
   {
  return DEVICE_INTERFACE_VERSION;   
   }
  
   MODULE_API unsigned GetNumberOfDevices()
  {
   return (unsigned) g_availableDevices.size();
   }
  
   MODULE_API bool GetDeviceName(unsigned deviceIndex, char* name, unsigned bufLen)
  {
   if (deviceIndex &gt;= g_availableDevices.size())
    return false;
  </code></pre>
  
  <p>Now the problem is it gives me an error C2491 (definition of dllimport function not allowed)
  I did research about this and it usually is when a function is defined when it is supposed to be declared, I have already defined the function in ModuleInterface.h and then used it in ModuleInterface.cpp but it still shows the same error.
  Can there be some other possibility for this error to occur? Or is there something wrong with the code?</p>