SWIG, Python, C++, and Coca-Cola

B

bressert

Hi Everyone,

Recently I have been working on building a module for Python from C++
code, with SWIG, and towards the end of compiling the various sets of
code I'm getting an error.

[comp:~/swig_project] user% swig -c++ -python example.i
[comp:~/swig_project] user% g++ -c example.cpp
[comp:~/swig_project] user% g++ -c example_wrap.cxx -I/scisoft/i386/
Packages/Python-2.4.3/Python.framework/Versions/2.4/include/python2.4/
example_wrap.cxx: In function 'PyObject* _wrap_main(PyObject*,
PyObject*)':
example_wrap.cxx:735: error: 'main' was not declared in this scope


The beginning of example.i looks like the following:

%module filename
%{
#define file_plugin "plugins/file.h"
#if foo_OS!=2
#include <pthread.h>
#endif
#include "../Foo.h"
using namespace foo_library;
%}


The error that is being picked up in reference to 'main' is contained
in the following excerpt, generated by SWIG (example_wrap.cxx):


/*-----------------------------------------------
@(target):= _filename.so
------------------------------------------------*/
#define SWIG_init init_filename

#define SWIG_name "_filename"

#define cimg_plugin "plugins/file.h"
#if foo_OS!=2
#include <pthread.h>
#endif
#include "../Foo.h"
using namespace foo_library;

#ifdef __cplusplus
extern "C" {
#endif
static PyObject *_wrap_main(PyObject *self, PyObject *args) {
PyObject *resultobj;
int arg1 ;
char **arg2 = (char **) 0 ;
int result;
PyObject * obj1 = 0 ;

if(!PyArg_ParseTuple(args,(char *)"iO:main",&arg1,&obj1)) goto
fail;
if ((SWIG_ConvertPtr(obj1,(void **) &arg2,
SWIGTYPE_p_p_char,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
result = (int)main(arg1,arg2);

resultobj = PyInt_FromLong((long)result);
return resultobj;
fail:
return NULL;
}

Any clues as to what is happening here or what to do next? If you
know, your help would greatly help. Thanks in advance!
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Any clues as to what is happening here or what to do next?

Apparently, it tries to wrap the main() function. It should
not do that: main should not be callable from Python. Most
likely, you have a declaration of main somewhere so it thinks
it should wrap it. You should not have a declaration of main,
anyway, so you should be safely able to drop that.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,708
Messages
2,569,347
Members
44,654
Latest member
7Jhamal74

Latest Threads

Top