Linux C Find a way to use libraries Cflags and Libs _c language

Source: Internet
Author: User
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:

$ Gcc-wall-o Test test.c

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

Related Article

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.