charlie | 14 Nov 22:56

Function Pointer Example not working

Hi All,

Yesterday I posted about the question I had of template function. This time I worked step step from examples in Doc 1.3 to reach my ultimate goal. But as I worked on the Function Pointer Example in 5.4.9 in Doc 1.3, it doesn't work. My platform is a Ubuntu linux with swig 1.3.36, python 2.5.2 and gcc 4.2.3.

The compiling and linking has no errors:

swig -python -c++ -o test_wrap.cpp test.i
python setup-test.py build
running build
running build_py
copying test.py -> build/lib.linux-i686-2.5
running build_ext
building '_test' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c test_wrap.cpp -o build/temp.linux-i686-2.5/test_wrap.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-i686-2.5/test_wrap.o build/temp.linux-i686-2.5/test.o -o build/lib.linux-i686-2.5/_test.so

But when I try to import test in python, it complains:
import _test
ImportError: ./_test.so undefined symbol: _Z9binary_opiiPFiiiE

My test.i is:
%module test
%{
#include "test.h"
%}
%include "test.h"

%callback("%s_cb");
int add( int, int ); //add_cb
int sub( int, int ); //sub_cb
int mul( int, int ); //mul_cb
%nocallback;

My test.h is:

int binary_op(int a, int b, int (*op)(int,int) );
int add( int a, int b ) { return a+b; }
int sub( int a, int b ) { return a-b; }
int mul( int a, int b ) { return a*b; }
// NOTE: this is func ptr from example in Doc 1.3: 5.4.9

It is really strange to me. I am a novice swigger but I really need its power to accelerate my development. Could anybody point out where my problem is?

TIA

Charlie

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 4 Dec 23:10
Favicon

Re: Function Pointer Example not working

charlie wrote:
> Hi All,
> 
> Yesterday I posted about the question I had of template function. This 
> time I worked step step from examples in Doc 1.3 to reach my ultimate 
> goal. But as I worked on the Function Pointer Example in 5.4.9 in Doc 
> 1.3, it doesn't work. My platform is a Ubuntu linux with swig 1.3.36, 
> python 2.5.2 and gcc 4.2.3. <http://4.2.3.>
> 
> The compiling and linking has no errors:
> 
> swig -python -c++ -o test_wrap.cpp test.i
> python setup-test.py build
> running build
> running build_py
> copying test.py -> build/lib.linux-i686-2.5
> running build_ext
> building '_test' extension
> gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall 
> -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c test_wrap.cpp -o 
> build/temp.linux-i686-2.5/test_wrap.o
> cc1plus: warning: command line option "-Wstrict-prototypes" is valid for 
> Ada/C/ObjC but not for C++
> g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions 
> build/temp.linux-i686-2.5/test_wrap.o build/temp.linux-i686-2.5/test.o 
> -o build/lib.linux-i686-2.5/_test.so
> 
> But when I try to import test in python, it complains:
> import _test
> ImportError: ./_test.so undefined symbol: _Z9binary_opiiPFiiiE
> 
A basic level of C/C++ knowledge is assumed for using SWIG; using 
c++filt should give you the clue as to what is missing:

$ c++filt _Z9binary_opiiPFiiiE
binary_op(int, int, int (*)(int, int))

William

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/

Gmane