Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9877 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46297 invoked by uid 1010); 16 May 2004 16:02:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 46213 invoked from network); 16 May 2004 16:02:11 -0000 Received: from unknown (HELO office-b.volomp.com) (195.178.35.94) by pb1.pair.com with SMTP; 16 May 2004 16:02:11 -0000 Received: from mravojed.office.kom (mravojed.office.kom [192.168.0.67]) by office-b.volomp.com (Postfix) with ESMTP id C146398173; Sun, 16 May 2004 17:57:55 +0200 (CEST) To: Peter 'iridium' Waller Cc: internals@lists.php.net In-Reply-To: <20040516030854.50210.qmail@pb1.pair.com> References: <20040516030854.50210.qmail@pb1.pair.com> Content-Type: text/plain Organization: MindNever Dot Org Message-ID: <1084723199.22864.161.camel@mravojed> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.4 Date: Sun, 16 May 2004 18:00:00 +0200 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Extension written in C++ and undefined symbols From: vladimir@mindnever.org (Vladimir Zidar) 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