For any poor person that ends up searching this list and comes up to this thread, in the config.m4 file add the lines
PHP_REQUIRE_CXX EXTRA_LDFLAGS=-lstdc++
Somewhere.
Also make sure that your file ends in the extension .cpp.
Peter.
Vladimir Zidar wrote:
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.
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php