Re: Extension written in C++ and undefined symbols

From: Date: Sun, 16 May 2004 16:00:00 +0000
Subject: Re: Extension written in C++ and undefined symbols
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-9877@lists.php.net to get a copy of this message
When you need to access function compiled from C++ source code, you need to declare it as extern "C", in order to tell the compiler to generate function name that is compatible with C. Otherwise, compiler will generate different name (will mangle it), and C won't be able to find it. So, write extern "C" blah() { ... } in test.cpp On Sun, 2004-05-16 at 05:08, Peter 'iridium' Waller wrote: > I've currently got some libraries written in C++ with various class > interfaces, I was going to write an interface between them and PHP but > got very stuck trying to get the extension to recognize any C++ linked > to it at all.. > > I spent quite a while searching the archives and google before posting > this, and found some advice telling me to set EXTRA_LDFLAGS = -lstdc++. > This seemed to fix the odd one or two things, I don't remember what now > because that was a while ago.. > > in my config.m4: > > PHP_NEW_EXTENSION(nalicity, nalicity.c test.cpp, $ext_shared) > > in test.cpp: > > void blah() > { > printf( "\n\nBlah\n\n" ); > } > > in nalicity.c > > PHP_FUNCTION(testfunction) > { > blah(); > } > > Doesn't work unless I rename test.cpp to test.c and change the > PHP_NEW_EXTENSION line accordingly. It compiles fine, I just get the error: > > /usr/bin/php: relocation error: > > /usr/lib/php/extensions/no-debug-non-zts-20020429/../../../../src/php/exts/nalicity/modules/nalicity.so: > > undefined symbol: blah > > when I try to run the PHP and load the dl(). As I said above though, > works fine as a plain old C file. Any ideas? I've stayed up all night > trying to figure it out but have gotten nowhere. > > (and on an unrelated note, is there any way I can specify an absolute > path to dl()? I feel kinda stupid with all those ../..'s in there.) > > Thanks in advance for any help, > > Peter. -- Vladimir Zidar, Programmer MindNever Foodstuff TRDG. Head Office Branch Tel: +381-63-550161, +385-98-9574261 http://www.mindnever.org, icq: 15414204, mail: mr_W@mindnever.org

« previous php.internals (#9877) next »