SWIG tutorial problems
<p>I'm trying to follow the swig tutorial but I've got stuck, right now I'm using:</p>

<ul>
<li>Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32</li>
<li>Vs2015 x64, Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23918 for x64</li>
<li>SWIG Version 3.0.10</li>
</ul>

<p>The contents are:</p>

<p><strong>example.c</strong></p>

<pre><code> #include &lt;time.h&gt;
 double My_variable = 3.0;

 int fact(int n) {
     if (n &lt;= 1) return 1;
     else return n*fact(n-1);
 }

 int my_mod(int x, int y) {
     return (x%y);
 }

 char *get_time()
 {
     time_t ltime;
     time(&amp;ltime);
     return ctime(&amp;ltime);
 }
</code></pre>

<p><strong>example.i</strong></p>

<pre><code> %module example
 %{
 /* Put header files here or function declarations like below */
 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
 %}

 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
</code></pre>

<p>Then I do:</p>

<ul>
<li><code>swig -python example.i</code></li>
<li><code>cl /D_USRDLL /D_WINDLL example.c example_wrap.c -Ic:\Python351\include /link /DLL /out:example.pyd /libpath:c:\python351\libs python35.lib</code></li>
</ul>

<p>But when I try <code>python -c "import example"</code> I get:</p>

<pre><code>Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
ImportError: dynamic module does not define module export function (PyInit_example)
</code></pre>

<p>Question, what's going on and how do i fix it?</p>

<p>The name of the dynamic-linked module for SWIG should begin with an underscore, in this case <code>_example.pyd</code>. The SWIG generated Python file is looking for the module named <code>_example</code>, see beginning of that file:</p>

<pre><code>from sys import version_info
if version_info &gt;= (2, 6, 0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:                                           # â SEE HERE
            fp, pathname, description = imp.find_module('_example', [dirname(__file__)])
        except ImportError:
            import _example # â AND HERE
            return _example # â AND HERE
        if fp is not None:
            try:                      # â AND HERE
                _mod = imp.load_module('_example', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _example = swig_import_helper() # â AND HERE
    del swig_import_helper
else:    # â AND HERE
    import _example
</code></pre>

<p>It is in fact the name of the C++ module that is wrapped by SWIG.</p>

python c++ windows visual-studio-2015 swig