cxmlxml-parsinglibxml2xml-libxml

whats the reason for the xml2-config not found while compiling libxml2?


The program is to run a c program to parse a xml file in windows Gcc mingw. but on compilation i get xml2-config not found ,--libs unrecognized commands, --cflags unrecognized commands.

gccenter image description here

i have added libxml files "libxml libxslt iconv" to the environmental path.

enter image description here


Solution

  • When you write a program that uses a third-party library like libxml, typically you have two problems:

    1. You need to tell the compiler where the library's header files are installed, so that when your code says things like #include <xml.h> the compiler will be able to find them.

    2. You need to tell the linker where the library itself is installed.

    If you don't manage to do step 1 correctly, you typically get an error like "error: 'xml.h' file not found".

    If you don't manage to do step 2 correctly, you typically get errors like "Undefined symbol: _xmlparse" or "library not found for -llibxml". ("Undefined symbol" means the compiler didn't even know to look for the library, so it complains that there are no definitions for the functions that would have been found in it. "library not found for -llibxml" means you told the compiler which library to look for, but it couldn't find it.)

    On C compilers under Unix, anyway, you tell the compiler where to look for header files using the -I flag, like this:

    cc -Idirectory_where_extra_header_files_are -c test.c
    

    You tell the compiler/linker to load an additional library using the -l flag:

    cc test.o -llibxml
    

    You tell the compiler/linker where to find that additional library using the -L flag:

    cc test.o -Ldirectory_where_extra_library_files_are -llibxml
    

    But this can be a nuisance. Many third-party libraries come with "config" programs which are supposed to help you with this. An invocation like

    xml-config --cflags
    

    prints the string

    -Idirectory_where_the_libxml_header_files_are
    

    so you know what to add to the cc line to fix problem 1. And the an invocation like

    xml-config --libs
    

    prints the string

    -Ldirectory_where_the_libxml_libraries_are -llibxml
    

    so you know what to add to the cc line to fix problem 2.

    And then, finally, this tool is intended to be used a special mechanism of the Unix shell, the backquote, which lets you take the output of one command and insert it into another command line:

    cc `xml-config --cflags --libs` test.c
    

    This literally runs the xml-config command, collects its output (that is, whatever xml-config prints out), and inserts that input into the command line, just as if you'd typed it, and then finally runs the cc command with those additional arguments. It's a handy mechanism, but if you're using Windows you may not be able to use it.

    So if you're on a Unix-like system and if the xml-config program is installed where the shell can find it and if the header files and libraries are installed where xml-config thinks they are, then using xml-config can be very convenient. But if any of these things is not true, the whole mechanism breaks down, and you may have to do things "by hand".

    Doing things "by hand" isn't impossible, and it isn't even particularly difficult. It's how we always did things back before this kind of "config" tool helper mechanism was invented. As discussed above, just use -I to tell the compiler where the header files are when you compile:

    cc -Idirectory_where_the_libxml_header_files_are -c test.c
    

    Use -L and -l to tell it where the library is:

    cc test.o -Ldirectory_where_the_libxml_libraries_are -llibxml