Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9880 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18945 invoked by uid 1010); 16 May 2004 20:19:41 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 18921 invoked from network); 16 May 2004 20:19:40 -0000 Received: from unknown (HELO smtp.nildram.co.uk) (195.112.4.54) by pb1.pair.com with SMTP; 16 May 2004 20:19:40 -0000 Received: from [192.168.0.3] (i.have.already.broken.in.to.your.localareanetwork.org [195.149.46.220]) by smtp.nildram.co.uk (Postfix) with ESMTP id B48D12735E0; Sun, 16 May 2004 21:19:36 +0100 (BST) Message-ID: <40A7CCDD.50600@beyondunreal.com> Date: Sun, 16 May 2004 21:19:41 +0100 User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502) X-Accept-Language: en, en-us MIME-Version: 1.0 To: Vladimir Zidar Cc: internals@lists.php.net References: <20040516030854.50210.qmail@pb1.pair.com> <1084723199.22864.161.camel@mravojed> In-Reply-To: <1084723199.22864.161.camel@mravojed> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Extension written in C++ and undefined symbols From: iridium@beyondunreal.com (Peter Waller) Thank you muchly. It took considerable trial and error but I got it working. 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. >> >>