compiling for Python

View: New views
2 Messages — Rating Filter:   Alert me  

compiling for Python

by almeida :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I all!!
I'm doing the introductory example of Swig, compiling a C code to  
include in Python. The sources file are:

/* File : example.c */

double My_variable = 3.0;

/* Compute factorial of n */
int fact(int n) {
        if (n <= 1) return 1;
        else return n*fact(n-1);
}

/* Compute n mod m */
int my_mod(int n, int m) {
        return(n % m);
}
---------------------------------
/* File : example.i */
%module example

%{
/* Put headers and other declarations here */
extern double My_variable;
extern int    fact(int);
extern int    my_mod(int n, int m);
%}

extern double My_variable;
extern int    fact(int);
extern int    my_mod(int n, int m);

Then i wrote:
swig -python example.i
gcc -c -fpic example.c example_wrap.c -I/usr/include/python2.5
gcc -shared example.o example_wrap.o -o _example.so

Then, in the python console, when i import the module, i get this:
>>> import example
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: ./example.so: wrong ELF class: ELFCLASS64

What's wrong? What's that mean?

I hope you help me...

Thanks








--
Lic. Yasser Almeida Hernández
Center of Molecular Inmunology (CIM)
Nanobiology Group
P.O.Box 16040, Havana 11600, Cuba
Phone: (537) 271-7933, ext. 221

----------------------------------------------------------------
Correo FENHI




------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: compiling for Python

by Josh Cherry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Thu, 1 Oct 2009, Yasser Almeida Hernández wrote:

> Then i wrote:
> swig -python example.i
> gcc -c -fpic example.c example_wrap.c -I/usr/include/python2.5
> gcc -shared example.o example_wrap.o -o _example.so
>
> Then, in the python console, when i import the module, i get this:
>>>> import example
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: ./example.so: wrong ELF class: ELFCLASS64
Since you're naming your shared library _example.so (as you should), there
shouldn't be any example.so to import.  You must have a different library
named example.so in your directory (or somewhere else on your Python path)
that takes precedence over example.py.  It might be a 64-bit library that
you're unintentionally loading into 32-bit Python, but in any case it's
going to cause you trouble.

Josh

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user