Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21946 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8445 invoked by uid 1010); 20 Feb 2006 01:08:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 8430 invoked from network); 20 Feb 2006 01:08:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2006 01:08:27 -0000 X-Host-Fingerprint: 64.233.162.207 zproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.162.207:8908] helo=zproxy.gmail.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 2C/BD-45151-A8619F34 for ; Sun, 19 Feb 2006 20:08:26 -0500 Received: by zproxy.gmail.com with SMTP id l8so850170nzf for ; Sun, 19 Feb 2006 17:08:22 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=UXlAJf702W6qp31f9V01HXAtBtrfxOLFGWoZwa2K7hE55Bqp1he1cgCFv4fGYpqaPtu6kdNm7aP9lh4UK00gaj/u5sbkrBiQsAXV9ouxdWdMHDhT5r9wSoCHJzPHC/QZRnw0/AqHqUDDJArhcnlXVkaSqCkO+WiYGKEVvLTXq2g= Received: by 10.36.129.13 with SMTP id b13mr4776670nzd; Sun, 19 Feb 2006 17:08:22 -0800 (PST) Received: by 10.36.101.5 with HTTP; Sun, 19 Feb 2006 17:08:22 -0800 (PST) Message-ID: <90e24d4e0602191708rd796490l63a5b6cae46efbdc@mail.gmail.com> Date: Sun, 19 Feb 2006 17:08:22 -0800 To: "Andrew Mather" Cc: internals@lists.php.net In-Reply-To: <008601c630ba$566e5740$ca5f8a51@VaioCen> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2723_20808433.1140397702739" References: <008601c630ba$566e5740$ca5f8a51@VaioCen> Subject: Re: [PHP-DEV] PHP / C++ Interaction From: phpdev@gmail.com ("Jeremy Johnstone") ------=_Part_2723_20808433.1140397702739 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 2/13/06, Andrew Mather wrote: > > - can I talk to a C++ library from PHP, either directly or via > a PHP/C extension? You could just have the PHP extension written in C++. There is no requirement of PHP extensions to be written in C, you just need to make sur= e you properly wrap the C parts inherited from the core w/ an extern C block. I have wrapped more than a handful of C++ libraries at my day job in into PHP extensions using more or less the following approach. Here's a rough overview of the changes needed (this list might not be complete, but should be close). config.m4 changes --------------------------------- I set the the compiler environment variables (aka CC and CXX) to both use g++. Not sure if this is necessary. In your included libraries (aka PHP_ADD_LIBRARY_WITH_PATH) make sure you include libstdc++ your source file changes ----------------------------------- Wrap the following in an extern "C" like shown below: extern "C" { #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_your_extension_name.h" } And later on further down wrap the following: extern "C" { #ifdef COMPILE_DL_YOUR_EXTENSION_NAME ZEND_GET_MODULE(your_extension_name) #endif } As best as I can remember, that is all that is necessary to write a C++ PHP Extension instead of a C one. Brighter minds on this list might know better if I am forgetting something, but I remember it being very minimal changes so I think the above is it. -Jeremy -- --------------------------- Jeremy Johnstone http://www.jeremyjohnstone.com jsjohnst@php.net ------=_Part_2723_20808433.1140397702739--