I am using libxml2 parser for parsing xml file. But when I compile using using gcc compiler:
gcc test.c note.xml -I/usr/include/libxml2 -lxml2 -o output
It gives me following error:
/usr/bin/ld:note.xml: file format not recognized; treating as linker script
/usr/bin/ld:note.xml:1: syntax error
collect2: error: ld returned 1 exit status
Here is my test.c file:
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
void readfile(const char* filename) {
xmlDocPtr doc;
doc = xmlReadFile(filename,NULL,0);
if(doc == NULL)
return;
xmlFreeDoc(doc);
}
int main(int argc,char* argv[]) {
if(argc != 2)
return 1;
LIBXML_TEST_VERSION
readfile(argv[1]);
xmlCleanupParser();
xmlMemoryDump();
return 0;
}
Here is my xml file:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The error explains it all:
/usr/bin/ld:note.xml: file format not recognized; treating as linker script
File format not recognized. Which file? note.xml
. Is it code? No, it isn't part of your C code. It should not be compiled at all, so don't pass it as an argument to gcc
.