473,329 Members | 1,484 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,329 software developers and data experts.

extend python with C embedded python+ Swig

Hello everyone
I am trying to use a module , which I have create by using Swig. This module has C code with embedded Python . The relative code follows :

Expand|Select|Wrap|Line Numbers
  1. // main.c
  2.  
  3. #include "Python.h"
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     Py_Initialize();
  9.     PyRun_SimpleString("execfile('aplo.py') \n");
  10.     Py_Finalize();
  11.     return 0;
  12. }
# aplo.py //this only print a string
Expand|Select|Wrap|Line Numbers
  1. print "hello, everything goes well."
Expand|Select|Wrap|Line Numbers
  1. /* example.i
  2.  
  3. %module example
  4.  
  5. %{
  6. #include "Python.h"
  7. int main();
  8. %}
  9. #include "Python.h"
  10. int main();
  11.  
  12.  
To wrap the aboves at a module I use Swig and by executing the following commands:

$ swig -python example.i
$ gcc -c example_wrap.c main.c -Dmain=oldmain -I/usr/include/python2.5
$ ld -shared example_wrap.o main.o -o _example.so
And then from command line i call python:
$ python
>>> import _example
>>>_example.main()
hello, everything goes well.
Segmentation fault (core dumped)

And the above message display.
What am I doing wrong ? Is there any solution ?
I appreciate any answer.
Thanks a lot
Oct 5 '07 #1
1 2072
Hello again
Did anyone knows if Swig support wrapping C code with embedded Python code? To do that is any special declarations that I have to introduce at interface file ?
Oct 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Chris | last post by:
Hi I am posting this on both the perl and python groups My intention is not to start a war or anything else, I would just like some pragmatic advice. My apologies to the python group I am...
1
by: Vio | last post by:
My story: I played with a little embedded python piece of code (python interpreter embedded in wxWidgets app), and used SWIG to extend this embedded py interpreter. I did it in Linux, after some...
13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
0
by: Derek Allen | last post by:
I'm using SWIG to generate glue code for my embedded/extended python app. There are a couple of very frustrating issues that I would like to see if anyone else has solutions for: - Once I have...
1
by: Arthur Chereau | last post by:
Hi, I'm trying to setup viewcvs to work with subversion 1.2.0 on Linux with Python 2.4.1. The last viewcvs (from CVS) needs subversion python bindings. I installed swig and built subversion from...
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...
6
by: matey | last post by:
I am have version 2.3.4. I want to write a python script to access a secure HTTPS. I tried the following: import urllib urllib.urlopen("https://somesecuresite.com") s = f.read() f.close()
0
by: Carl Douglas | last post by:
Hi Python fans, I am developing a DLL that is loaded by a host application on windows. I'm using python 2.5. My DLL uses an embedded python interpreter which can access the host application...
2
by: mr_gees100_peas | last post by:
Hi, I've been trying for days to make either boost.python or swig to work for me. The one I have gotten the closest to is boost. Note that this is for windows XP. I'm not much of an unix person...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.