سؤال

وأنا أكتب تمديد PHP5، وبينما كنت يمكن أن يكتب في C، سيكون من الأسهل استخدام C ++ والاستفادة من STL وزيادة.

والمشكلة هي ان الدروس رأيت نتعامل الا مع C، وأنا أبحث عن مثال الأساسي الذي يستخدم C ++

وهنا هو ما حاولت حتى الآن:

config.m4

[ --enable-hello   Enable Hello World support])

if test "$PHP_HELLO" = "yes"; then
  AC_DEFINE(HAVE_HELLO, 1, [Whether you have Hello World])
  PHP_NEW_EXTENSION(hello, hello.cpp, $ext_shared)
fi

php_hello.h

ملاحظة محاولة مني للإعلان عن البتات التي PHP واجهات مع باسم خارجي ... "C"

#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_entry;
#define phpext_hello_ptr &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_functions[] = {
    PHP_FE(hello_world, NULL)

    {NULL, NULL, NULL}
};

zend_module_entry hello_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
    STANDARD_MODULE_HEADER,
#endif
    PHP_HELLO_WORLD_EXTNAME,
    hello_functions,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
#if ZEND_MODULE_API_NO >= 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);
}

.... وهنا أخطاء بناء بلدي:

إذا كنت phpize وتكوين وجعل هذا، وأحصل على ما يلي (وإخراجها عن وضوح)

$ make
/bin/bash /home/paul/php5/php-5.2.8/ext/hello2/libtool 
   --mode=compile  
   -I. 
   -I/home/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/ext/hello2/main 
   -I/home/paul/php5/php-5.2.8/ext/hello2 
   -I/usr/local/include/php 
   -I/usr/local/include/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  
   -DHAVE_CONFIG_H     
   -c /home/paul/php5/php-5.2.8/ext/hello2/hello.cpp 
   -o hello.lo 
libtool: compile: unrecognized option `-I.'
libtool: compile: Try `libtool --help' for more information.
make: *** [hello.lo] Error 1

وأظن أنا بحاجة إلى مزيد من العمل به إلى config.m4 من أجل إنشاء MAKEFILE العمل ولكن أنا جميلة جديدة لtoolchain دول مجلس التعاون الخليجي.

وإذا كان يساعد، وأنا تستهدف فقط فب 5.2.6+، وفقط على لينكس (على وجه التحديد، أوبونتو 8.04). بناء بيئتي يستخدم أوبونتو 8.10، وذلك باستخدام 4.3.2 دول مجلس التعاون الخليجي

ومؤشرات تلقى بامتنان!

هل كانت مفيدة؟

المحلول

وبعد نشر جئت عبر CodeGen_PECL مما يخلق تمديد الهيكل العظمي من وصف XML تستند من التمديد. ويشمل ذلك علامة تجعل من إخراج C ++

وكذلك التأكد من ملف الرأس المستخدمة خارجي "C"، تضمن ملف حزب الشعب الكمبودي ولدت أيضا ZEND_GET_MODULE (مرحبا) كان داخل خارجي "C" كتلة أيضا.

وكما هو متوقع، كان أكبر الفرق في ملف M4، الذي يشبه هذا:

dnl
dnl $ Id: $
dnl

PHP_ARG_ENABLE(hello, whether to enable hello functions,
[  --enable-hello         Enable hello support])

if test "$PHP_HELLO" != "no"; then
  PHP_REQUIRE_CXX
  AC_LANG_CPLUSPLUS
  PHP_ADD_LIBRARY(stdc++,,HELLO_SHARED_LIBADD)
  export OLD_CPPFLAGS="$CPPFLAGS"
  export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_HELLO"

  AC_MSG_CHECKING(PHP version)
  AC_TRY_COMPILE([#include <php_version.h>], [
#if PHP_VERSION_ID < 40000
#error  this extension requires at least PHP version 4.0.0
#endif
],
[AC_MSG_RESULT(ok)],
[AC_MSG_ERROR([need at least PHP 4.0.0])])

  export CPPFLAGS="$OLD_CPPFLAGS"


  PHP_SUBST(HELLO_SHARED_LIBADD)
  AC_DEFINE(HAVE_HELLO, 1, [ ])

  PHP_NEW_EXTENSION(hello, hello.cpp , $ext_shared)

fi

وهكذا، إذا كنت تعاني من نفس المشكلة، استخدم CodeGen_PECL أو تكييف عينة M4 فوق (وكذلك التأكد من أنك قد استخدمت خارجي "C" في رأس وحول الماكرو ZEND_GET_MODULE)

نصائح أخرى

وهناك أيضا هذا متسرع مقدمة إلى التفاف فئة (وتصدير وظائف في الدرجة :: أسلوب الطريقة) هنا: http://devzone.zend.com/article/4486

وبالنسبة لي الجزء الأكثر فائدة هو خطوط لإضافة لمترجم C ++ / ربط قواعد config.m4 لphpize.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top