Greetings All,<br><br>I'm using SWIG for the first time and am running into some problems.  I've tried researching at swig.org and python.org, but unfortunately, most of the examples use programs I don't have, such as Solaris, Unix, and Irix.  I wish to make my C++ classes and functions accessible from Python, and create the glue code necessary to interface with my compiler.  I'm using Python 2.4, MS Visual Studio 2005, and Windows XP command prompt.<br><br>C++ Code:<br>/* FuncTest.h */<br><br>#include <time.h><br><br>int fact(int n)<br>{<br>    if(n <=1) return 1;<br>    else return n*fact(n-1);<br>}<br><br>char *get_time()<br>{<br>    time_t ltime;<br>    time(&ltime);<br>    return ctime(&ltime);<br>}<br><br>Interface File:<br>/* example.i */<br>%module example<br>%{<br>#include "FuncTest.h"<br>%}<br><br>%include "FuncTest.h"<br><br>Command Prompt
 Input:<br>c:\Utilities\Swig\swig -python -c++ example.i<br><br>example.py and example_wrap.cxx are then created.  <br><br>This is where I hit the wall.  example_wrap.cxx can't be included in my project because it creates 2 linker errors:<br> <br>error LNK2005: _SWIG_init already defined in Main.obj    PENT_wrap.obj<br>fatal error LNK1169: one or more multiply defined symbols found    C:\My Work\PEntityTest\Release\PEntityTest.exe    1<br><br>These errors are because of this chunk of code created by SWIG:<br>#ifdef __cplusplus<br>extern "C"<br>#endif<br>SWIGEXPORT void SWIG_init(void) {<br>  PyObject *m, *d;<br>  <br>  /* Fix SwigMethods to carry the callback ptrs when needed */<br>  SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);<br>  <br>  m = Py_InitModule((char *) SWIG_name, SwigMethods);<br>  d = PyModule_GetDict(m);<br>  <br> 
 SWIG_InitializeModule(0);<br>  SWIG_InstallConstants(d,swig_const_table);<br>  <br>  <br>}<br><br>I can't import the example.py module because the generated script tries to import _example.<br><br>I assume this file is created in another step that I haven't figured out how to do yet. The SWIG tutorial instructs the following:<br><pre>unix % swig -python example.i<br> unix % gcc -c example.c example_wrap.c \<br>        -I/usr/local/include/python2.1<br> unix % ld -shared example.o example_wrap.o -o _example.so </pre>I believe this is what I need to do, but using XP command prompt.<br><br>Any feedback on any one little chunk of this huge post would be helpful.<br><br>Much thanks.<br><br>-Mich<br><br><br><br><br><p>
        
                <hr size=1> Yahoo! Mail<br> 
<a href="http://us.rd.yahoo.com/mail_us/taglines/pmall2/*http://photomail.mail.yahoo.com">Use Photomail</a> to share photos without annoying attachments.