简体   繁体   English

PHP的C ++扩展

[英]C++ extensions for PHP

I need to write C++ extensions for PHP OS Linux (Debian), 我需要为PHP OS Linux(Debian)编写C ++扩展,

1. Created the file config.m4: 1.创建文件config.m4:

PHP_ARG_ENABLE (test, Enable test support)

if test "$ PHP_TEST" = "yes"; then
   AC_DEFINE (HAVE_TEST, 1 , [You have test extension])
   PHP_ADD_INCLUDE (/ home / oleg / PROJECTS / QT / lib_swl / include)
   PHP_ADD_LIBRARY (stdc + +, 1 , TEST_SHARED_LIBADD)
   PHP_NEW_EXTENSION (test, test.c, $ ext_shared)
fi

2 . 2。 Wrote the text of C++ program test.c 编写了C ++程序test.c的文本

# include "php.h"
# include "zend_config.h"

ZEND_BEGIN_ARG_INFO_EX (arginfo_readdata, 0,0,2)
ZEND_ARG_INFO ( 1 , param1)
ZEND_END_ARG_INFO ();

PHP_FUNCTION (test);

const zend_function_entry test_functions [] =
{
    PHP_FE (test, arginfo_readdata)
    {NULL, NULL, NULL}
} ;

zend_module_entry test_module_entry = {
    STANDARD_MODULE_HEADER, / / ​​# if ZEND_MODULE_API_NO> = 20010901
    "test", / / ​​name of the module
    test_functions, / / ​​specify exported functions
    NULL, / / ​​PHP_MINIT (test), Module Initialization
    NULL, / / ​​PHP_MSHUTDOWN (test), Module Shutdown
    NULL, / / ​​PHP_RINIT (test), Request Initialization
    NULL, / / ​​PHP_RSHUTDOWN (test), Request Shutdown
    NULL, / / ​​PHP_MINFO (test), Module Info ( for phpinfo ())
    "0.1" , / / version of our module
    STANDARD_MODULE_PROPERTIES
} ;

ZEND_GET_MODULE (test)

PHP_FUNCTION (test)
{
zval * parameter;

if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, "z", & parameter) == FAILURE)
return;


/ * Check for parameter being passed by reference * /
if (! PZVAL_IS_REF (parameter))
{
zend_error (E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL ();
}

/ * Make changes to the parameter * /
ZVAL_LONG (parameter, 123) ;
}

Caused in this directory: 造成此目录:

phpize phpize

./config ./config中

make 使

make install 进行安装

it works well .... 它运作良好....

BUT ... There I need to use an external static library swl.a How can I connect it? 但是...我需要使用外部静态库swl.a 如何连接它? Field LIBS =-lswl.a this does't work. 字段LIBS = -lswl.a无效。 Thanks. 谢谢。

I did it! 我做的!

Needed to add this strings in config.m4: 需要在config.m4中添加以下字符串:

PHP_SUBST(TEST_SHARED_LIBADD)
PHP_ADD_LIBRARY_WITH_PATH(swl, "/home/oleg/PROJECTS/QT/lib_swl", TEST_SHARED_LIBADD)

Here we have added static library swl.a 在这里我们添加了静态库swl.a

what's all... 什么...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM