0

Background: I'm writing an extension to PHP in C and C++, using boost libraries. The C extension-hooks call into some extern "C"'ed C++ code.

I'm getting my_extension.so: undefined symbol: _ZNKSt13runtime_error4whatEv in Unknown on line 0

What I thought was happening (and I could be wrong) is an exception in C++ code is getting thrown back at the C code that is calling it, and thus choking. Though I'm not sure because I just went and wrapped all the C++ code with try/catch(...) and this is still happening.

The other thing is I do not get this error on CentOS 5.6, but I do get it on CentOS 6.5, even compiling this extension on 6.5. I did build the php from sources on 6.5, so maybe I'm missing a library? Php otherwise works fine.

I have no idea how to troubleshoot this, as PHP decides not to load this library and then keeps running. gdb doesn't even catch it.

Here is the exact error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/php54/lib/php/extensions/no-debug-non-zts-20100525/my_extension.so' - /usr/local/php54/lib/php/extensions/no-debug-non-zts-20100525/my_extension.so: 
  undefined symbol: _ZNKSt13runtime_error4whatEv in Unknown on line 0

edit If I link my extension to a simple executable with a main() and call some of the C++ methods I have, it works fine.

ldd is showing a dependency on libstdc++.so in my test executable, but not in my shared library my_extension.so. I don't know how to make it have this dependency in the .so

edit 2

I found the shared library is getting put together by cc rather than g++. If I manually make the shared library with g++, everything works.

#  cc -shared  src/.libs/all_my_dot_o_files.o  -Wl,-soname -Wl,my_extension.so -o .libs/my_extension.so

vs.

#  g++ -shared  src/.libs/all_my_dot_o_files.o  -Wl,-soname -Wl,my_extension.so -o .libs/my_extension.so

So I just need to figure out how to make this php autoconf cr@p use g++ instead of cc.

Cœur
  • 37,241
  • 25
  • 195
  • 267
marathon
  • 7,881
  • 17
  • 74
  • 137
  • 2
    This is not an exception - it is an error generated by the runtime linker. When your program starts up, the runtime linker attempts to resolve undefined symbols by looking in all the shared libraries (.so files) that are advertised by the program as dependencies. Normally you can list these dependencies with the `ldd` command. It looks like the symbol translates to `std::runtime_error::what() const` (using c++filt). This normally happens when you have a missing or mismatched dependency to the C++ runtime library. – Jordan Samuels Aug 11 '14 at 17:22
  • 1
    Maybe the answers posted here can help you in making the build system use g++: http://stackoverflow.com/questions/1110682/extending-php-with-c – Claudi Aug 11 '14 at 18:04
  • 1
    @Claudix Thanks! That post had the solution - a flag to tell autoconf to use g++ for everything fixed the problem. – marathon Aug 16 '14 at 19:58

0 Answers0