How to use pkg-config in php extension development
First of all, let’s learn about what pkg-config can do. Here is what Wikipedia says about pkg-config:
pkg-config is computer software that provides a unified interface for querying installed libraries when compiling software from source code. pkg-config was originally designed for Linux, but now there are versions available on various versions of BSD, Windows, Mac OS X, and Solaris.
Simply put, pkg-config mainly provides the following functions:
1. Check the version number of the library. If the version of the required library does not meet the requirements, it will print out an error message to avoid linking the wrong version of the library file.
2. Obtain compilation preprocessing parameters, such as macro definitions and the location of header files.
3. Obtain link parameters, such as the location of libraries and other dependent libraries, file names and other connection parameters.
4. Automatically add settings for other libraries it depends on.
Recently developed a php extension for image cropping using opencv. Opencv needs to load a lot of so libraries. It is too troublesome to manually add them to config.m4, and it does not take advantage of post-maintenance. Fortunately, opencv provides the opencv.pc file, so you can use pkg-config to automatically obtain the compiled parameters.
The following is the code I wrote in config.m4 to automatically load opencv related so libraries and header files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
Note:
Please do not use braces in the conditional part of if, otherwise there will be syntax errors in the makefile generated by m4.
Reference document
http://www.chenjunlu.com/2011/03/understanding-pkg-config-tool/ "Understanding pkg-config tool"
http://www.php.net/manual/zh/internals2 .buildsys.configunix.php "Interacting with UNIX build systems: config.m4"

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
