Undefined when loading php extension using SWIG

I am trying to download a PHP extension made using SWIG, but when I start PHP, I get the following error:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/libtg.so' - /usr/lib/php5/20090626/libtg.so: undefined symbol: __gxx_personality_v0 in Unknown on line 0 

The extension I'm trying to download is called libtg.so and compiled with the command:

 g++ -shared libtg_wrap.o -o libtg.so 

where libtg_wrap.o is the object file for the shell code generated by SWIG.

The missing __gxx_personality_v0 character is in libstdc++.so , as seen in the following command:

 $ nm -D /usr/lib/libstdc++.so.6 | grep __gxx_personality_v0 00000000000b9990 T __gxx_personality_v0 

libstdc++.so refers to libtg.so , as can be seen from the following command:

 $ ldd libtg.so linux-vdso.so.1 => (0x00007fff5f932000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f3fc937c000) libm.so.6 => /lib/libm.so.6 (0x00007f3fc90f9000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f3fc8ee2000) libc.so.6 => /lib/libc.so.6 (0x00007f3fc8b5f000) /lib64/ld-linux-x86-64.so.2 (0x00007f3fc98fc000) 

so I don’t understand why he cannot find the character. Any ideas on how I can debug this?

+7
source share
1 answer

It seems that somewhere in the compilation process, the compiler or linker did not know about the C ++ source.

When I tried swig (also to create a php extension), I created the following Makefile , which may be convenient in your case, so you can configure it for your project and try, it is quite difficult.

See how I need to specify the "-C ++" parameter for the swig command. Also, be sure to add the .cpp extension for the source files and add "-lstdC ++" to your linker flags.

An important material should be a call to swig (note the -C ++ parameter):

 ${OUTPUTDIR}/${NAME}_swig.cpp: ${SWIG} -outdir ${OUTPUTDIR} \ -oh ${OUTPUTDIR}/${NAME}_swig.h \ -o ${OUTPUTDIR}/${NAME}_swig.cpp \ -c++ -php \ ${NAME}.i 

and the linker call (note the -lstdc flag):

 ld -shared ${OUTPUTDIR}/*.o -o ${OUTPUTDIR}/${NAME}.so -lstdc++ 

Hope this helps

+1
source

All Articles