[php-src]Php擴充的多檔案編譯

來源:互聯網
上載者:User

標籤:

內容均以php5.6.14為例.

 

假設有模組 foo,php_foo.h 和 foo.c 是固有檔案,額外的C檔案如果要加入編譯,大致有五步。

 

1. 新增標頭檔 foo_bar.h

#ifndef FOO_BAR_H#define FOO_BAR_Hextern zend_class_entry *foo_bar_ce;#endif

 

2. 新增主檔案 foo_bar.c,裡面的兩個標頭檔要加.

#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_foo.h"  // #1.#include "foo_bar.h"  // #2.zend_class_entry *foo_bar_ce;zend_function_entry foo_bar_methods[] = {     {NULL, NULL, NULL}};FOO_STARTUP_FUNCTION(bar) {    zend_class_entry ce;     /* init class entry */    INIT_CLASS_ENTRY(ce, "Foo_Bar", foo_bar_methods);    /* register */    foo_bar_ce = zend_register_internal_class(&ce TSRMLS_CC);    /* flags */    return SUCCESS;}

 

3. 標頭檔 php_foo.h 新定義宏

#define FOO_STARTUP_FUNCTION(module)    ZEND_MINIT_FUNCTION(foo_##module)#define FOO_STARTUP(module)             ZEND_MODULE_STARTUP_N(foo_##module)(INIT_FUNC_ARGS_PASSTHRU)#define FOO_SHUTDOWN_FUNCTION(module)   ZEND_MSHUTDOWN_FUNCTION(foo_##module)#define FOO_SHUTDOWN(module)            ZEND_MODULE_SHUTDOWN_N(foo_##module)(SHUTDOWN_FUNC_ARGS_PASSTHRU)

 

4. 主檔案 foo.c 中引入新增的標頭檔,並在 MINIT 階段啟動新增模組

#include "php_foo.h"#include "foo_bar.h"  // #1.
/* startup component */FOO_STARTUP(conf);    // #2.

 

5. config.m4 增加新的C檔案

PHP_NEW_EXTENSION(foo,     foo.c                             foo_bar.c                         , $ext_shared)

 

這最後要注意的也是最重要的,由於更改了m4檔案,須重新執行從 phpize 開始的安裝步驟使之生效。

不然你將得到一個錯誤 php: symbol lookup error.

 

Link: http://www.cnblogs.com/farwish/p/5696878.html

@黑眼詩人 <www.farwish.com>

[php-src]Php擴充的多檔案編譯

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.