PHP extension 2: some basic macro definitions and locations in config. M4

Source: Internet
Author: User

Php_arg_with or php_arg_enable specifies the working mode of the PHP module. Select either of them.
Php_require_cxx is used to specify that the extension uses C ++
Php_subst (extern_name_shared_libadd) is used to demonstrate how this extension is compiled into a dynamic link library.
Php_add_library (stdc ++, "", sysfile_shared_libadd) is used to link the Standard C ++ Library to the extension
Php_new_extension is used to specify which source files should be compiled and separated by spaces.

The default module framework generated by ext_skel is for C. To use C ++, the three or five macros above are required. in addition, testext. C is renamed to testext. CPP, so php_new_extension originally included testext. C also needs to be modified.

  1. After using C ++, pay attention to a small problem, that is, the php_testext.h file may be referenced by other parts of PHP, And the quotor may be. c file, so it cannot contain anything unique to C ++ in php_testext.h. for example, the standard template library, class, or bool type.

  2. Testext. C (now renamed testext. CPP). It already contains a test-type export function. You can use that example to understand how to add your own function. zend_function_entry is the list of exported functions. zend_module_entry describes the module information. but because it is C ++, there are several points to modify:

    1. # Include "php. H" # include "php_ini.h" # include "ext/standard/info. H"

      Use extern "c" to modify.

    2. Zend_get_module must also be modified with extern "C"

    3. Zend_module_entry is the type used to describe the module information. It is actually a structure, and the second item does not know what it means. in Windows, it seems to be a description, which can be a long string, but in Linux it seems that it can only be the same as the module name.

  3. The subsequent work is to write your own code. According to the design, provide external interface functions, and then write C/C ++ code for implementation.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.