I usually code in PHP, and new to Visual Studio and C, I followed the steps here — http://www.codeguru.com/cpp/data/data-misc/xml/article.php/c14893/Libxml2-Everything-You-Need-in-an-XML-Library.htm and downloaded three files — libxml, iconv, zlib. It says, iconv and zlib are dependencies for libxml2.
My code is below:
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
static void print_element_names(xmlNode * a_node)
{
xmlNode *cur_node = NULL;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
printf("node type: Element, name: %s\n",
cur_node->name);
}
print_element_names(cur_node->children);
}
}
int main(int argc, char **argv)
{
xmlDoc *doc = NULL;
xmlNode *root_element = NULL;
if (argc != 2) return(1);
LIBXML_TEST_VERSION // Macro to check API for match with
// the DLL we are using
/*parse the file and get the DOM */
if (doc = xmlReadFile("http://www.w3schools.com/xml/note.xml", NULL, 0)) == NULL){
printf("error: could not parse file %s\n", argv[1]);
exit(-1);
}
/*Get the root element node */
root_element = xmlDocGetRootElement(doc);
print_element_names(root_element);
xmlFreeDoc(doc); // free document
xmlCleanupParser(); // Free globals
return 0;
}
In my downloaded package, I have folders — iconv-1.9.2.win32, libxml2-2.7.8.win32, zlib-1.2.5.win32. [all these folders are lying side by side inside workspace\libxml
folder]
I downloaded above from here — ftp://ftp.zlatkovic.com/libxml/
I entered the following path in Project Properties:
Project > Properties > C/C++->General > Additional Include Directories
— workspace\libxml\libxml2-2.7.8.win32\libxml2-2.7.8.win32\include
Project > Properties > Linker > General > Additional Library Directories
— workspace\libxml\iconv-1.9.2.win32\iconv-1.9.2.win32\include
I have no idea where to put zlib
folder path. (first question)
I built the solution in Visual Studio Professional 2015 (Windows 8, 64 bit) and got the following errors:
cannot open source file "iconv.h"
C1083 Cannot open include file: 'iconv.h': No such file or directory
GTK: I created: File > Project > VC++ > Empty Project
My questions are:
Where should I put, which specific path from all the three folders (from the downloaded package)?
I have to create standalone application, so I have to statically link the libxml2 Dll, am I going right?
when setting up the search paths...
1) for the compiles, there will be 3 search paths, that each end in include.
2) for the libraries, there will be 3 search paths that each end in lib.
So the main problem is the paths to the *.h files needs to be expanded to have all three paths.
The paths to the libraries, needs to be expanded to have all three paths AND those paths needs to end at the directories that contain the libraries, not the directories that contain the header files.