Undefined symbol when loading php extension made with SWIG
c++, libstdc++, php, shared-libraries, swig
Solution
It seems that somewhere in your compile process, the compiler or linker was not aware of a c++ source.
When I tried swig (also to create a php extension), I created the following Makefile that may be handy in your case, so you may want to customize it for your project and give it a try, it's pretty straighforward.
See how I had to specify the "-c++" option to the swig command. Also, be sure to have .cpp extension for your source files and add "-lstdc++" to your linker flags.
The important stuff should be the swig invocation (note the -c++ option):
${OUTPUTDIR}/${NAME}_swig.cpp:
${SWIG} -outdir ${OUTPUTDIR} \
-oh ${OUTPUTDIR}/${NAME}_swig.h \
-o ${OUTPUTDIR}/${NAME}_swig.cpp \
-c++ -php \
${NAME}.i
and the linker invocation (note the -lstdc flag) :
ld -shared ${OUTPUTDIR}/*.o -o ${OUTPUTDIR}/${NAME}.so -lstdc++
Hope it helps
Problem
I am trying to load a PHP extension made using SWIG, but I am getting the following error when starting PHP: ``` 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 am trying to load is named `libtg.so` and was compiled with the command: ``` g++ -shared libtg_wrap.o -o libtg.so ``` where `libtg_wrap.o` is the object file for the wrapper code generated by SWIG. The missing symbol `__gxx_personality_v0` is found in `libstdc++.so`, as evident from the following command: ``` $ nm -D /usr/lib/libstdc++.so.6 | grep __gxx_personality_v0 00000000000b9990 T __gxx_personality_v0 ``` `libstdc++.so` is referenced in `libtg.so`, as evident 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 see why it cannot find the symbol. Any ideas on how I can further debug this?