title: Getting my python c++ extension to compile using Swig and Distutils on Windows
body: <p>I'm trying to create a python c++ extension on windows. My problem is that I can't seem to generate the .pyd file (link error) even after using swig and distutils. Below is step by step what I did:</p>
  
  <p>In Microsoft Visual Studio 2010 I created a class
  Hello.cpp:</p>
  
  <pre><code>#include "StdAfx.h"
  #include "Hello.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  
  Hello::Hello(void)
  {
  }
  
  void Hello::greeting(void){
     cout&lt;&lt;"Hello World!!"&lt;&lt;endl;
  
  }
  
  
  
  Hello::~Hello(void)
  {
  }
  </code></pre>
  
  <p>Hello.h:</p>
  
  <pre><code>      #pragma once
        class Hello
        {
           public:
              Hello(void);
              ~Hello(void);
              void greeting(void);
        };  
  </code></pre>
  
  <p>Then I created an .i file HelloWorld.i</p>
  
  <pre><code>%module HelloWorld
  
  %{
  #include "Hello.h"
  %}
  
  %include "Hello.h"
  </code></pre>
  
  <p>Then I swigged </p>
  
  <pre><code>swig -c++ -python -o Hello_wrap.cpp HelloWorld.i
  </code></pre>
  
  <p>This seemed to have worked successfully, generating the files I expected it would. Next I created setup.py.</p>
  
  <pre><code>from distutils.core import setup, Extension
  
  module1=Extension('HelloWorld', sources=['Hello.cpp'])
  
  setup(name='Hello_Package', version='1.0', description='This is a demo', \
        ext_modules=[module1])
  </code></pre>
  
  <p>With that written and after switching into the directory where all the files are stored together, I entered into the command line </p>
  
  <pre><code>python setup.py build
  </code></pre>
  
  <p>Unfortuantely, this is the error I get</p>
  
  <pre><code>running build
  running build_ext
  building 'HelloWorld' extension
  creating build
  creating build\temp.win32-2.7
  creating build\temp.win32-2.7\Release
  c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
  3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /TpHello.cpp /Fobuild\tem
  p.win32-2.7\Release\Hello.obj
  Hello.cpp
  c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning C
  4530: C++ exception handler used, but unwind semantics are not enabled. Specify
  /EHsc
  creating build\lib.win32-2.7
  c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCRE
  MENTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild /EXPORT:initHel
  loWorld build\temp.win32-2.7\Release\Hello.obj /OUT:build\lib.win32-2.7\HelloWor
  ld.pyd /IMPLIB:build\temp.win32-2.7\Release\HelloWorld.lib /MANIFESTFILE:build\t
  emp.win32-2.7\Release\HelloWorld.pyd.manifest
  LINK : error LNK2001: unresolved external symbol initHelloWorld
  build\temp.win32-2.7\Release\HelloWorld.lib : fatal error LNK1120: 1 unresolved
  externals
  error: command '"c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe"'
  failed with exit status 1120
  </code></pre>
  
  <p>What do I do about this link error? I'm assuming swig and distutils are working correctly, so I wouldn't have to change the code. Help please! Thanks</p>