Many times, some special libraries are used to compile and executeProgramYou need to add additional cflags and libs. Otherwise, the system will prompt that the specified header file or "undefined reference to..." error message cannot be found.
If the libxml API is used in test. C
$ Gcc-wall-O test. c
An error message is displayed.
Run
$ Ls/usr/lib/pkgconfig/| grep libxmllibxml-2.0.pc
$ CAT/usr/lib/pkgconfig/libxml-2.0.pc prefix =/users =/usrlibdir =/usr/libincludedir =/usr/includemodules = 1 Name: libxmlversion: 2.6.26description: 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 obtain
$ PKG-config libxml-2.0 -- cflags -- libs-I/usr/include/libxml2-lxml2-LZ-LM
Therefore, during compilation, you only need to execute
$ Gcc-wall 'pkg-config libxml-2.0 -- cflags -- libs'-O test. c