How does php c extension call a third-party library?

Source: Internet
Author: User
Php c extension how to call a third-party library because I am writing C, so I am not very familiar with this matter, the first note is that the program in linux, php version is 5.3.13, I can use a simple addition operation php extension written in C. I think the problem is that there is no correct link to the C library. There are two types of C library: 1. is the C extension of PHP that comes with the linux system itself. how does one call a third-party library?
I am writing C, so I am not very familiar with this matter. First of all, I would like to explain that the php version is 5.3.13 in linux, I can use a simple addition operation php extension written in C. I think the problem is that there is no correct link to the C library.
The C library has two types:
1. it is provided by the linux system, but it must be linked with-l when compiling executable files in gcc, such as the C thread library-lpthread.

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

I wrote the function for php to call.
C/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);}

Added in config. m4

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 the generated test. so and C third-party library libdecode. so are copied to/usr/local/php/lib/php/extension/no-debug-non-zts-20090626
Now I have added the following statements in php. ini:
Extension = test. so
Extension = libdecode. so

Finally, the php_setcode function cannot be successfully called in php.

Ask where I need to add the above steps to implement the call to php_setcode

------ Solution --------------------
If you want to implement the c processing function or want php to call a user-defined function, why not make the latter a php extension?
If the former: http://blog.csdn.net/franzhong/article/details/7265429
------ Solution --------------------
I don't know. I have to find a tutorial on the internet. from the principle point of view, php should include the header file, and the dl series should dynamically load the interfaces in the dynamic library during execution, you need to tell php which interfaces are exposed by your dynamic library.
------ Solution --------------------
To the parent directory of your custom extension, it should be the ext directory. See how the extension is actually implemented, such as mysql
------ Solution --------------------
# Clear
Make clean

# Add a module ncdocxml
./Configure -- with-php-config =/usr/nc-home/php5/bin/php-config -- enable-ncdocxml

# Compiling module ncdocxml
Make LDFLAGS =-lncdocxml
------ Solution --------------------
You are talking about static loading. you only have so and there is no corresponding lib file or header file. Static loading is not possible.
What you need is dynamic loading, which is of course completed in the c program. For example, the BC in the window has the LoadLibrary function to load the specified dll. of course, it is still very painful to have no header file.

In addition, we have been dynamically loading the dynamic link library of the operating system in both vb and vfp to complete the work that the script language cannot do.
------ Solution --------------------
Help you find this blog 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.