How to find the cflags and libs library in linux c

Source: Internet
Author: User

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

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.