title: error LNK2001: unresolved external symbol __imp__Py_InitModule4
body: <p>I'm trying to extend Python with C++. I'm using Visual C++ 2008 and Python 2.7. I have had a lot of problems building the .dll file, and finally when it seemed to be everything correct, I can't stop getting this error:</p>
  
  <p>error LNK2001: unresolved external symbol  _<em>imp</em>_Py_InitModule4 </p>
  
  <p>I know it isn't a linker error because I had this error before (it gave me the error but with all kind of <em>Py</em>_... functions) and I had resolved that. </p>
  
  <p>I don't know if this is an important data but I have build python27_d.dll with VC++ 2008 too. </p>
  
  <p>This is the code:</p>
  
  <pre><code>#include "Python.h"
  
  #include &lt;windows.h&gt;
  
  #include &lt;string.h&gt;
  
  #include &lt;tchar.h&gt;
  
  #include &lt;stdlib.h&gt;
  
  #include &lt;Aclapi.h&gt;
  
  struct file_perms {
  
    char user_domain[2050];
  
     unsigned long user_mask;
  
  };
  
  
  
  
   void lookup_sid ( ACCESS_ALLOWED_ACE* pACE, char user_domain[] ) {
  
    char username[1024]="";
  
   char domain[1024]="";
  
  
  
  ULONG len_username = sizeof(username);
  
  ULONG len_domain = sizeof(domain);
  
  PSID pSID =(PSID)(&amp;(pACE-&gt;SidStart));
  
  SID_NAME_USE sid_name_use;         
  
  
  LPWSTR username1 = reinterpret_cast&lt;LPWSTR&gt;( username );
  LPWSTR domain1 = reinterpret_cast&lt;LPWSTR&gt;( domain );
  if (!LookupAccountSid(NULL, pSID, username1, &amp;len_username, domain1, &amp;len_domain, &amp;sid_name_use)){  
  
      strcpy(user_domain, "unknown");
  
  } else {
  
      strcat(user_domain,domain);
  
      strcat(user_domain,"\\");
  
      strcat(user_domain,username);
  
  }
  
  
  
  
  
  }
  
  
  
  
  
  
  
  
  
  
  
  void acl_info( PACL pACL, ULONG AceCount, file_perms fp[]){     
  
  for (ULONG acl_index = 0;acl_index &lt; AceCount;acl_index++){
  
      ACCESS_ALLOWED_ACE* pACE;
  
  
  
      if (GetAce(pACL, acl_index, (PVOID*)&amp;pACE))         
  
      {       
  
          char user_domain[2050]="";  
  
          lookup_sid(pACE,user_domain);
  
          strcpy(fp[acl_index].user_domain,user_domain);
  
          fp[acl_index].user_mask=(ULONG)pACE-&gt;Mask;
  
      }
  
  }
  
  }
  
  
  
  static PyObject *get_perms(PyObject *self, PyObject *args)
  
  {
  
  
  
  PyObject *py_perms = PyDict_New();
  
  //get file or directory name
  
  char *file;
  
  
  
  if (!PyArg_ParseTuple(args, "s", &amp;file))
  
      return NULL;
  
  
  
  //setup security code
  
  PSECURITY_DESCRIPTOR pSD;
  
  PACL pDACL; 
  
  //GetNamedSecurityInfo() will give you the DACL when you ask for
  
  //DACL_SECURITY_INFORMATION. At this point, you have SIDs in the ACEs contained in the DACL. 
  
  LPWSTR file1 = reinterpret_cast&lt;LPWSTR&gt;( file );
  
  ULONG result = GetNamedSecurityInfo(file1,SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, 
  
  &amp;pDACL, NULL, &amp;pSD);
  
  
  
  if (result != ERROR_SUCCESS){ return NULL;}
  
  if (result == ERROR_SUCCESS){
  
      ACL_SIZE_INFORMATION aclSize = {0};
  
      if(pDACL != NULL){   
  
          if(!GetAclInformation(pDACL, &amp;aclSize, sizeof(aclSize),
  
              AclSizeInformation)){
  
              return NULL;
  
          }
  
      }
  
  
  
      file_perms *fp = new file_perms[aclSize.AceCount];
  
      acl_info(pDACL, aclSize.AceCount, fp );
  
  
  
      //Dict
  
      for (ULONG i=0;i&lt;sizeof(fp);i++){
  
          PyObject *domain = Py_BuildValue("s",fp[i].user_domain);
  
          PyObject *user = Py_BuildValue("s",fp[i].user_mask);
  
          PyDict_SetItem(py_perms,domain,user);
  
      }
  
  }
  
  return py_perms;
  
  };
  
  
  
  
  
  
  
  
  
  
  
  
  
  static PyMethodDef fileperm_methods[] = {
  
  { "get_perms", get_perms, METH_VARARGS, "Execute a shell command." },
  
  { NULL, NULL, 0, NULL }
  
  };
  
  
  extern "C"
  __declspec(dllexport)
  void init_fileperm(void)
  {
  PyObject *m=Py_InitModule("fileperm",fileperm_methods);
  
  return;
  }
  </code></pre>
  
  <p>I'm working in Windows 7 64bits.</p>
  
  <p>I know that Py_InitModule is deprecated for Python 3 but I'm working in Python27 (2.7.3 ).</p>
  
  <p>Does someone know why I get this error?</p>
  
  <p>Thanks!</p>