PHP5加载|安装外部C动态库
来源:互联网 发布:java怎么打成jar 编辑:程序博客网 时间:2024/04/30 22:08
[1] cd php-5.3.9/ext
[2] ./ext_skel --extname=ncdocxml
[3] cd ncdocxml
[4] nano -w config.m4
############
删除 3 个 dnl
dnl PHP_ARG_WITH(my_module, for my_module support,
dnl Make sure that the comment is aligned:
dnl [ --with-my_module Include my_module support])
或者删除 下边这3个 dnl
dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,
dnl Make sure that the comment is aligned:
dnl [ --enable-my_module Enable my_module support])
############
[5] nano -w ncdocxml.c
############
[6] nano -w php_ncdocxml.h
############
[7] /usr/local/php5/bin/phpize --with-apxs2=/usr/local/apache/bin/apxs
[8] apt-get install autoconf
[9] ./configure --with-ncdocxml --with-php-config=/usr/local/php5/bin/php-config
[10] nano -w Makefile
############
/*修改*/
EXTRA_LIBS=-lncdocxml
############
[11] make clean; make LDFLAGS=-lncdocxml
[12] ldd modules/ncdocxml.so
############
linux-gate.so.1 => (0xb772e000)
libncdocxml.so => /usr/local/lib/libncdocxml.so (0xb76a5000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb755e000)
libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0xb7435000)
libz.so.1 => /usr/local/lib/libz.so.1 (0xb741f000)
libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb7406000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb73e0000)
/lib/ld-linux.so.2 (0xb772f000)
libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb73dc000)
libiconv.so.2 => /usr/local/lib/libiconv.so.2 (0xb72fd000)
############
[13] make install
############
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-zts-20090626/
############
[14] nano -w /etc/php.ini
############
extension = /usr/local/php5/lib/php/extensions/no-debug-zts-20090626/ncdocxml.so
############
[2] ./ext_skel --extname=ncdocxml
[3] cd ncdocxml
[4] nano -w config.m4
############
删除 3 个 dnl
dnl PHP_ARG_WITH(my_module, for my_module support,
dnl Make sure that the comment is aligned:
dnl [ --with-my_module Include my_module support])
或者删除 下边这3个 dnl
dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,
dnl Make sure that the comment is aligned:
dnl [ --enable-my_module Enable my_module support])
############
[5] nano -w ncdocxml.c
############
/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2012 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+*//* $Id: header 321634 2012-01-01 13:15:04Z felipe $ */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_ini.h"#include "ext/standard/info.h"#include "php_ncdocxml.h"#include "/usr/local/libncdocxml.h"/*extern int NcXmlDocGetClass(char * infile); *//* If you declare any globals in php_ncdocxml.h uncomment this:ZEND_DECLARE_MODULE_GLOBALS(ncdocxml)*//* True global resources - no need for thread safety here */static int le_ncdocxml;/* {{{ ncdocxml_functions[] * * Every user visible function must have an entry in ncdocxml_functions[]. */const zend_function_entry ncdocxml_functions[] = { PHP_FE(confirm_ncdocxml_compiled, NULL) /* For testing, remove later. */ PHP_FE(ncdocxml, NULL) PHP_FE_END /* Must be the last line in ncdocxml_functions[] */};/* }}} *//* {{{ ncdocxml_module_entry */zend_module_entry ncdocxml_module_entry = {#if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER,#endif "ncdocxml", ncdocxml_functions, PHP_MINIT(ncdocxml), PHP_MSHUTDOWN(ncdocxml), PHP_RINIT(ncdocxml), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(ncdocxml), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(ncdocxml),#if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */#endif STANDARD_MODULE_PROPERTIES};/* }}} */#ifdef COMPILE_DL_NCDOCXMLZEND_GET_MODULE(ncdocxml)#endif/* {{{ PHP_INI *//* Remove comments and fill if you need to have entries in php.iniPHP_INI_BEGIN() STD_PHP_INI_ENTRY("ncdocxml.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_ncdocxml_globals, ncdocxml_globals) STD_PHP_INI_ENTRY("ncdocxml.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_ncdocxml_globals, ncdocxml_globals)PHP_INI_END()*//* }}} *//* {{{ php_ncdocxml_init_globals *//* Uncomment this function if you have INI entriesstatic void php_ncdocxml_init_globals(zend_ncdocxml_globals *ncdocxml_globals){ ncdocxml_globals->global_value = 0; ncdocxml_globals->global_string = NULL;}*//* }}} *//* {{{ PHP_MINIT_FUNCTION */PHP_MINIT_FUNCTION(ncdocxml){ /* If you have INI entries, uncomment these lines REGISTER_INI_ENTRIES(); */ return SUCCESS;}/* }}} *//* {{{ PHP_MSHUTDOWN_FUNCTION */PHP_MSHUTDOWN_FUNCTION(ncdocxml){ /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS;}/* }}} *//* Remove if there's nothing to do at request start *//* {{{ PHP_RINIT_FUNCTION */PHP_RINIT_FUNCTION(ncdocxml){ return SUCCESS;}/* }}} *//* Remove if there's nothing to do at request end *//* {{{ PHP_RSHUTDOWN_FUNCTION */PHP_RSHUTDOWN_FUNCTION(ncdocxml){ return SUCCESS;}/* }}} *//* {{{ PHP_MINFO_FUNCTION */PHP_MINFO_FUNCTION(ncdocxml){ php_info_print_table_start(); php_info_print_table_header(2, "ncdocxml support", "enabled"); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES();}/* }}} *//* Remove the following function when you have succesfully modified config.m4 so that your module can be compiled into PHP, it exists only for testing purposes. *//* Every user-visible function in PHP should document itself in the source *//* {{{ proto string confirm_ncdocxml_compiled(string arg) Return a string to confirm that the module is compiled in */PHP_FUNCTION(confirm_ncdocxml_compiled){ char *arg = NULL; int arg_len, len; char *strg; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "ncdocxml", arg); RETURN_STRINGL(strg, len, 0);}/* }}} *//* The previous line is meant for vim and emacs, so it can correctly fold and unfold functions in source code. See the corresponding marks just before function definition, where the functions purpose is also documented. Please follow this convention for the convenience of others editing your code.*//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */PHP_FUNCTION(ncdocxml){ char *dbg = NULL; int dbg_len, len; int result; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dbg, &dbg_len) == FAILURE){ return; } result = NcXmlDocGetClass(dbg); RETURN_LONG(result);}############
[6] nano -w php_ncdocxml.h
############
/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2012 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+*//* $Id: header 321634 2012-01-01 13:15:04Z felipe $ */#ifndef PHP_NCDOCXML_H#define PHP_NCDOCXML_Hextern zend_module_entry ncdocxml_module_entry;#define phpext_ncdocxml_ptr &ncdocxml_module_entry#ifdef PHP_WIN32# define PHP_NCDOCXML_API __declspec(dllexport)#elif defined(__GNUC__) && __GNUC__ >= 4# define PHP_NCDOCXML_API __attribute__ ((visibility("default")))#else# define PHP_NCDOCXML_API#endif#ifdef ZTS#include "TSRM.h"#endifPHP_MINIT_FUNCTION(ncdocxml);PHP_MSHUTDOWN_FUNCTION(ncdocxml);PHP_RINIT_FUNCTION(ncdocxml);PHP_RSHUTDOWN_FUNCTION(ncdocxml);PHP_MINFO_FUNCTION(ncdocxml);PHP_FUNCTION(confirm_ncdocxml_compiled); /* For testing, remove later. */PHP_FUNCTION(ncdocxml);/* Declare any global variables you may need between the BEGIN and END macros here: ZEND_BEGIN_MODULE_GLOBALS(ncdocxml) long global_value; char *global_string;ZEND_END_MODULE_GLOBALS(ncdocxml)*//* In every utility function you add that needs to use variables in php_ncdocxml_globals, call TSRMLS_FETCH(); after declaring other variables used by that function, or better yet, pass in TSRMLS_CC after the last function argument and declare your utility function with TSRMLS_DC after the last declared argument. Always refer to the globals in your function as NCDOCXML_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory.*/#ifdef ZTS#define NCDOCXML_G(v) TSRMG(ncdocxml_globals_id, zend_ncdocxml_globals *, v)#else#define NCDOCXML_G(v) (ncdocxml_globals.v)#endif#endif /* PHP_NCDOCXML_H *//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */############
[7] /usr/local/php5/bin/phpize --with-apxs2=/usr/local/apache/bin/apxs
[8] apt-get install autoconf
[9] ./configure --with-ncdocxml --with-php-config=/usr/local/php5/bin/php-config
[10] nano -w Makefile
############
/*修改*/
EXTRA_LIBS=-lncdocxml
############
[11] make clean; make LDFLAGS=-lncdocxml
[12] ldd modules/ncdocxml.so
############
linux-gate.so.1 => (0xb772e000)
libncdocxml.so => /usr/local/lib/libncdocxml.so (0xb76a5000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb755e000)
libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0xb7435000)
libz.so.1 => /usr/local/lib/libz.so.1 (0xb741f000)
libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb7406000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb73e0000)
/lib/ld-linux.so.2 (0xb772f000)
libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb73dc000)
libiconv.so.2 => /usr/local/lib/libiconv.so.2 (0xb72fd000)
############
[13] make install
############
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-zts-20090626/
############
[14] nano -w /etc/php.ini
############
extension = /usr/local/php5/lib/php/extensions/no-debug-zts-20090626/ncdocxml.so
############
[15] /usr/local/apache/bin/apachectl restart
[16] nano -w loadmoudle.php
############
<?php if (!extension_loaded("ncdocxml")) { echo "无法加载 ncdocxml.so !".PHP_EOL; } else { echo "加载 ncdocxml.so !".PHP_EOL; #调用加载的ncdocxml($filename)函数 $res = ncdocxml("/usr/local/test.txt"); print_r($res); }?>############
[17] /usr/local/php5/bin/php /usr/local/loadmoudle.php
############
加载 ncdocxml.so !
Array(
[0]=>success
)
############
0 0
- PHP5加载|安装外部C动态库
- QLibrary 动态加载外部库文件
- QLibrary 动态加载外部库文件
- 动态加载外部脚本
- Qt 调用外部C动态库
- 动态加载外部链接JS
- android动态加载外部类
- QTP运行时,动态加载外部共享对象库
- VC中加载外部动态链接库的步骤:
- 动态加载动态库(C#)反射
- php5安装GD库
- 动态加载并复制外部图片
- 动态加载外部css或js文件
- 转4种动态加载外部JavaScript
- 面试题目:动态加载外部JS
- ApplicationDomain与动态加载外部swf
- cocos2d js 如何动态加载外部图片
- Unity3D 动态加载外部MovieTexture视频
- Linux下JNI的实现
- 对IOS设备中UDID的一些思考
- quick-cocos2dx transition
- WINCE SD 驱动学习
- 越千年,是谁负了这情长
- PHP5加载|安装外部C动态库
- iOS 动画1
- An interested program for cookie
- linux定时任务 掉mysql 存储过程
- win7 x64 下VC6的调试程序无法退出的问题解决方法
- *.tar.gz文件包安装
- win7下架设IIS其他电脑无法访问的解决办法
- 解决MSSQL 2008不能用IP登录的问题
- Hibernate 4中buildSessionFactory()过时