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. The compiling error comes up when using g+
+.

=======================================================
[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!
 
R

red floyd

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. The compiling error comes up when using g+
+.

=======================================================
[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);

There are several errors, one of which is made clear by the error
message. Where is main() declared?

Second, main already returns int(). Per ISO/IEC 14882:2003 main ALWAYS
returns int.

Third, you are calling main(). Per ISO/IEC 14882:2003 you are not
allowed to call main.
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top