473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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!

Apr 6 '07 #1
1 1662
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
Apr 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jon Moldover | last post by:
Hi, I'm using Python in my win32 app by linking to the python23.dll. I'm trying to expose some c++ code in my app to Python so I can make application calls from Python scripts (according to the...
0
by: Andrew Collier | last post by:
hello, i am not sure whether this problem relates to swig, python or my c++ compiler. +please forgive me if this is inappropriately posted but i am sure that someone +on this list must have some...
0
by: Helmut Zeisel | last post by:
I want to build a static extension of Python using SWIG and VC++ 6.0 as described in http://www.swig.org/Doc1.3/Python.html#n8 for gcc. My file is testerl.i: ========================= %module...
3
by: It's me | last post by:
I am playing around with SWING building a Python module using the no brainer example in http://www.swig.org/tutorial.html. With that first example, /* File : example.c */ #include <time.h>...
1
by: Java and Swing | last post by:
I am trying to wrap some C code I have. Currently I have something like... defs.h ----------- typedef unsigned long MY_DIGIT; myapp.c ------------- void MakeDigits(MY_DIGIT digits) {
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
10
by: Bart Ogryczak | last post by:
Hi, I´m looking for some benchmarks comparing SWIG generated modules with modules made directly with C/Python API. Just how much overhead does SWIG give? Doing profile of my code I see, that it...
1
by: cody314 | last post by:
Versions: Python 2.5.1 (r251:54863, May 14 2007, 10:50:04) SWIG Version 1.3.20 Hello I have some code that wraps a C++ library so I may use it in python. The code basically just gets some data...
1
by: Uberman | last post by:
I have a bit of a odd arrangement here with SWIG, Python, Embedded Python and C++ classes exported into Python. Here's the plot: I have a class defined in a C++ DLL library. I am wrapping this...
0
by: Basha J P M | last post by:
I am beginner in python. I am working through the tutorial examples from http://www.swig.org/ and have run into some problems. I took the following command instructions from the tutorial on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.