By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

Python : segmentation fault

P: 16
Hello everyone
I try to extend Python using a simple C wrapped module . This module includes embedded python code and it is product of Swig . The corresponding files follows :

Expand|Select|Wrap|Line Numbers
  1. //main.c
  2. #include "Python.h"
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.     Py_Initialize();
  8.     PyRun_SimpleString("execfile('simple.py') \n");
  9.     Py_Finalize();
  10.     return 0;
  11. }
Expand|Select|Wrap|Line Numbers
  1. //simple.py
  2.  
  3. print " Hello, everyone"
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();
Expand|Select|Wrap|Line Numbers
  1. //extend.py
  2.  
  3. import _example
  4. _example.main()


The file main.c embeds python , which only execute the file simple.py. The example.i is the interface file , which is used from Swig to generate the desirable module _example.so . This module called from script python file, extend.py for execution.

To do those things from Linux command prompt I execute the following commands:

$ swig -python example.i
$gcc -c main.c example_wrap.c -Dmain=oldmain -I/usr/include/python2.5
$ld -shared example_wrap.o main.o -o _example.so
$python extend.py
Hello everyone
Segmentation fault (core dumped)

Why does the last message appear ? Swig supports wrapping of embedded with python , C code? Do you have any idea how to solve this problem ?I will appreciate any answers .
Thanks a lot
Oct 8 '07 #1
Share this Question
Share on Google+
1 Reply


bartonc
Expert 5K+
P: 6,596
The swig users mail list is actually quite good.
Oct 8 '07 #2

Post your reply

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