Many times, when using some special libraries to compile executable programs, you need to add additional CFLAGS and LIBS. otherwise, the system will prompt that the specified header file cannot be found or "undefined reference... "error message.
If the libxml api is used in test. c
Copy codeThe Code is as follows: $ gcc-Wall-o test. c
An error message is displayed.
RunCopy codeThe Code is as follows: $ ls/usr/lib/pkgconfig/| grep libxml
Libxml-2.0.pc
Copy codeThe Code is as follows: $ cat/usr/lib/pkgconfig/libxml-2.0.pc
Prefix =/usr
Exec_prefix =/usr
Libdir =/usr/lib
Includedir =/usr/include
Modules = 1
Name: libXML
Version: 2.6.26
Description: libXML library version2.
Requires:
Libs:-L $ {libdir}-lxml2-lz-lm
Cflags:-I ${includedir}/libxml2
Here, Libs and Cflags are the required information. You can use the following command to obtainCopy codeThe Code is as follows: $ pkg-config libxml-2.0 -- cflags -- libs
-I/usr/include/libxml2-lxml2-lz-lm
Therefore, during compilation, you only need to executeCopy codeThe Code is as follows: $ gcc-Wall 'pkg-config libxml-2.0 -- cflags -- libs'-o test. c