How C extensions for PHP call third-party libraries

Source: Internet
Author: User
Tags what interface
How C extensions for PHP call third-party libraries
Because I am writing C's so not very understanding of this thing, first of all, it is the program under Linux, PHP version is 5.3.13, I write a simple addition to C PHP extension can be used, I think the problem is not the right link into the C library
There are two types of C libraries:
1. It is the Linux system itself, but need to be in the GCC compile executable file with-l to link, such as C line libraries-lpthread

2. is a third party, for example, I now have a C. So dynamic link library libdecode.so, provides a C API function long Setcode (long l_input);

The function I rewritten for PHP calls is written like this.
C + + code
  
   Php_function (Php_setcode) {Long arg_1 = 0;long re = 0;if (Zend_parse_parameter (Zend_num_args () tsrmls_cc, "L", &arg_1 ) = = FAILURE) {return;} Re = Setcode (arg_1);}

Config.m4 added a

Php_add_library_with_path (decode,/home/wzb/lib, Test_shared_libadd)
Php_add_include (/home/wzb/include)

Execute command
./congfigure--with-php-config=/usr/local/php/bin/php-config
Make


and copied the generated test.so and C's third-party library libdecode.so to/usr/local/php/lib/php/extension/no-debug-non-zts-20090626.
Now I have added the following statement in PHP.ini
Extension=test.so
Extension=libdecode.so

Finally, the Php_setcode function cannot be successfully called in PHP.

Ask the above steps where I need to add to implement a call to Php_setcode

------Solution--------------------
Do you want to implement the C processing function or do you want PHP to call the custom function, if the latter is not made PHP extension?
If the former: http://blog.csdn.net/franzhong/article/details/7265429
------Solution--------------------
I do not understand, online to find a tutorial toss and toss it, from the principle point of view, PHP has to include the header file, the implementation of the DL series dynamically loading the interface in the dynamic library, you need to tell PHP what interface is your dynamic library burst out of the leak.
------Solution--------------------
To the parent directory of the custom extension you generated, it should be the Ext directory. See how the extension is actually implemented, such as MySQL
------Solution--------------------
#清除
Make clean

#添加模块ncdocxml
./configure--with-php-config=/usr/nc-home/php5/bin/php-config--enable-ncdocxml

#编译模块ncdocxml
Make Ldflags=-lncdocxml
------Solution--------------------
You said that is static loading, you only so do not have the corresponding Lib file and header file. is not possible to implement static loading
What you need is dynamic loading, which of course is done in the C program. For example, the BC under window has the LoadLibrary function to load the specified DLL, of course, no header file is still very painful

In addition, we have been in VB, VFP has been dynamic loading operating system dynamic link library to complete the script language is impossible to complete the work
------Solution--------------------
help you find this blog post for reference http://blog.csdn.net/offbye/article/details/6832536
  • 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.