How to use pkg-config in php extension development

Source: Internet
Author: User
First, what can pkg-config do. The following is a description of pkg-config in Wikipedia.

First, what can pkg-config do. The following describes pkg-config in Wikipedia:
Pkg-config is a computer software that provides a unified interface used to query installed libraries when compiling software from the source code. Pkg-config was originally designed for Linux, but it is now available in various versions of BSD, windows, Mac OS X, and Solaris.
To put it simply, pkg-config mainly provides the following functions:

1. check the database version number. If the required Library version does not meet the requirements, it prints an error message to avoid link to the library file of the wrong version.
2. obtain the pre-compilation parameters, such as macro definition and header file location.
3. obtain the link parameters, such as the location of the database and other dependent libraries, file names, and other connection parameters.
4. automatically add the settings of other dependent libraries.

Recently, a php extension for image cropping was developed using opencv. Opencv requires a lot of so libraries to be loaded. it is too troublesome to manually add them to config. m4 without using post-maintenance. Fortunately, opencv provides the opencv. pc file so that you can use pkg-config to automatically obtain the compiled parameters.

The following is the code for automatically loading the so Library and header file related to opencv written in config. m4.


Dnl # -- with-tclip-> check with-path SEARCH_PATH = "/usr/lib/pkgconfig" # define the pkgconfig file, that is, the file storage path of the pc extension SEARCH_FOR = "opencv. pc "# find the file if test-r $ PHP_TCLIP/$ SEARCH_FOR; then # TCLIP_DIR = $ PHP_TCLIP else # search default path list AC_MSG_CHECKING ([for tclip files in default path]) for I in $ SEARCH_PATH; do if test-r $ I/$ SEARCH_FOR; then TCLIP_DIR = $ I AC_MSG_RESULT (found in $ I) fi done fi dnl if test-z "$ TCLIP_DIR"; then AC_MSG_RESULT ([not found]) AC_MSG_ERROR ([Please reinstall the tclip distribution]) fi OPENCV_FLAGS = "'pkg-config opencv -- libs -- cflags opencv '" for I in $ OPENCV_FLAGS; do if test $ {I: 0: 2} = "-I "; then PHP_ADD_INCLUDE ($ {I: 2}) elif test $ {I :$ # I}-3} = ". so "; then dir_name = 'dirname $ I 'file_name =_name {I/$ dir_name/} file_name =$ {file_name/\/lib/} file_name =$ {file_name /. so/} PHP_ADD_LIBRARY_WITH_PATH ($ file_name, $ dir_name, TCLIP_SHARED_LIBADD) fi done

Note:
Do not use braces for the if condition. Otherwise, the makefile generated by m4 contains a syntax error.

References
Http://www.chenjunlu.com/2011/03/understanding-pkg-config-tool/ understanding pkg-config tool
Interaction with UNIX build systems: config. m4 http://www.php.net/manual/zh/internals2.buildsys.configunix.php


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.