Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21947 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11419 invoked by uid 1010); 20 Feb 2006 01:24:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 11404 invoked from network); 20 Feb 2006 01:24:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2006 01:24:18 -0000 X-Host-Fingerprint: 192.38.9.232 gw2.emini.dk Linux 2.4/2.6 Received: from ([192.38.9.232:6765] helo=gw2.emini.dk) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 23/0E-45151-04A19F34 for ; Sun, 19 Feb 2006 20:24:16 -0500 Received: from foxbox (IGLD-84-228-50-112.inter.net.il [84.228.50.112]) by gw2.emini.dk (Postfix) with ESMTP id D0A4BA3D26; Mon, 20 Feb 2006 02:24:11 +0100 (CET) Message-ID: <0d9401c635bc$6506dc30$6402a8c0@foxbox> Reply-To: "Steph Fox" To: "Jeremy Johnstone" , "Andrew Mather" Cc: References: <008601c630ba$566e5740$ca5f8a51@VaioCen> <90e24d4e0602191708rd796490l63a5b6cae46efbdc@mail.gmail.com> Date: Mon, 20 Feb 2006 03:24:26 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Subject: Re: [PHP-DEV] PHP / C++ Interaction From: steph@zend.com ("Steph Fox") Just search the archives, or the zend weeklies index page (http://www.zend.com/zend/week/) if you're short of time. I remember linking to someone's material regarding C++ extensions for PHP a few months back, and it'll be in the 'item descriptions' there. - Steph ----- Original Message ----- From: "Jeremy Johnstone" To: "Andrew Mather" Cc: Sent: Monday, February 20, 2006 3:08 AM Subject: Re: [PHP-DEV] PHP / C++ Interaction 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 sure 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