Many times, with special libraries, you need to add additional cflags and LIBS when compiling executable programs. Otherwise, you will be prompted not to find the specified header file or "Undefined reference to ..." The error message.
If the Libxml API is used in the program test.c, direct
Copy Code code as follows:
An error message is prompted.
Perform
Copy Code code as follows:
$ ls/usr/lib/pkgconfig/| grep libxml
libxml-2.0.pc
Copy Code code 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
Of these, Libs and cflags are the required information. You can use the following command to get
Copy Code code as follows:
$ pkg-config libxml-2.0--cflags--libs
-i/usr/include/libxml2-lxml2-lz-lm
Therefore, at compile time, you only need to perform
Copy Code code as follows:
$ Gcc-wall ' pkg-config libxml-2.0--cflags--libs '-O test test.c