I am writing a PHP5 extension, and when I can write it in C, it is easy to use C ++ The advantage of STL and Boost is
The problem is that I have only seen the deal with C, and I am looking for a basic example that uses C ++
so far tried Is:
config.m4
[- Enable Hello Hello World support]) If the test is "$ PHP_HELLO" = "Yes"; So AC_DEFINE (HAVE_HELLO, 1, [you're Hello World]) PHP_NEW_EXTENSION (Hello, hello.cpp, $ ext_shared) fi
php_hello.h
Note my bits the attempt to declare that PHP as well as in exile "C" interface
#ifndef PHP_HELLO_H #define PHP_HELLO_H 1 extern "C" {#define PHP_HELLO_WORLD_VERSION "1.0" #define PHP_HELLO_WORLD_EXTNAME " Hello "PHP_FUNCTION (Hello world); Extern zend_module_entry hello_module_interree; #define phpext_hello_ptr & amp; hello_module_entry} #endif
hello.cpp
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php. h" #include " Php_hello.h "static function_entry hello_function [] = {PHP_FE (hello_world, tap) {NULL, NULL, NULL}}; Zend_module_entry hello_module_entry = {#if ZEND_MODULE_API_NO & gt; = 20010901 STANDARD_MODULE_HEADER, #endif PHP_HELLO_WORLD_EXTNAME, Halo_kriya, null, zero, zero, zero, zero, #if ZEND_MODULE_API_NO & gt; = 20010901 PHP_HELLO_WORLD_VERSION, #endif STANDARD_MODULE_PROPERTIES}; #ifdef COMPILE_DL_HELLO ZEND_GET_MODULE (Hello) #endif PHP_FUNCTION (Hello_World) {RETURN_STRING ("Hello World", 1); }
.... and here are my build errors:
If I phpize, configure and make it, then I (the redesigned for clarity) Gets
$ make / bin / bash /home/paul/php5/php-5.2.8/ext/hello2/libtool --mode = compile -I I / house / Paul / PHP5 / php-5.2.8 / ext / hello2 -DPHP_ATOM_INC I / home / Paul / PHP5 / php-5.2.8 / ext / hello2 / include I / home / Paul / PHP5 / php -5.2.8 / Characters / Hello 2 / Main-I / Home / Paul / PHP5 / PHP-5.8 / XHT / Hello 2-Eye / USR / Local / Included / PHP-Eye / USA / Local / included / php / main I / usr / local / include / php / TSRM-I / usr / local / include / php / zend -i / usr / local / include / php / ext -i / usr / local / Include / php / ext / date / lib-DHHAVE_CONFIG_H -c /home/paul/php5/php-5.2.8/ext/hello2/hello.cpp -o hello.lo libtool: compilation:. Non-recognized option `I 'Libtool: Compile: For more information, try' libtool --help ': *** [Hello] Hello error 1
I doubt I'm working more on config.m4 to create working messaging, but I'm new to GCC Toolchain.
If this helps, then I'm targeting PHP 5.2.6+ only, and only on Linux (in particular, Ubuntu 8.04). My build environment is using Ubuntu 8.10, using GCC 4.3.2
Indicator Thanks! After posting I created a skeleton extension from an XML-based description of the extension which came after posting
There is a tag in it, C ++
In addition to ensuring the header file using the output "C", the JP CPP file also ensured that Jade EdJEDML (Hello) is an external " C "was also inside the block.
As expected, the biggest difference M 4 file, which looks like this:
dnl dnl $ Id: $ dnl PHP_ARG_ENABLE (Hello, Hello Work To enable, enable [- Enable Hello Hello support]) If the test is "$ PHP_HELLO" = "no"; Then the PHP_REQUIRE_CXX AC_LANG_CPBRUSPLUS PHP_ADD_LIBRARY (stdc ++, HELLO_SHARED_LIBADD) export OLD_CPPFLAGS = "$ CPPFLAGS" export is included in CPPFLAGS = "$ CPPFLAGS $-DHHAVHLLO" AC_MSG_CHECKING (PHP version) AC_TRY_COMPILE ([#include & lt; php_version.h & gt; ], [#if PHP_VERSION_ID] & lt; 40000 #Error This extension must have at least PHP version 4.0.0 #endif], [AC_MSG_RESULT (OK)], [AC_MSG_ERROR ([least needed PHP 4.0.0]] ) Export CPPFLAGS = "$ OLD_CPPFLAGS" PHP_SUBST (requires HELLO_SHARED_LIBADD) AC_DEFINE (HAVE_HELLO, 1, []) PHP_NEW_EXTENSION (hello, hello CPP, $ ext_shared) fi
Therefore, if you Are struggling with the same problem, users Make or adapt the above M4 sample (as well as to make sure that you have used "C" in your header and around the ZEND_GET_MODULE macro)
Comments
Post a Comment