Results 1 to 5 of 5
hi, i'm new on Linux and i have some problems compiling my program.
iḿ trying to parse a file using html parser by libxml.
Code:
#include <stdio.h>
#include <libxml/HTMLparser.h>
#include ...
- 01-13-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 3
undefined reference to
hi, i'm new on Linux and i have some problems compiling my program.
iḿ trying to parse a file using html parser by libxml.
when i compile (gcc -o html -I/usr/include/libxml2 tracker-extract-xml.c) i receive this message:Code:#include <stdio.h> #include <libxml/HTMLparser.h> #include <string.h> void main(){ printf("main\n"); htmlDocPtr doc; void* pd; char *filename; xmlSAXHandler handler = { NULL, /* internalSubset */ NULL, /* isStandalone */ NULL, /* hasInternalSubset */ NULL, /* hasExternalSubset */ NULL, /* resolveEntity */ NULL, /* getEntity */ NULL, /* entityDecl */ NULL, /* notationDecl */ NULL, /* attributeDecl */ NULL, /* elementDecl */ NULL, /* unparsedEntityDecl */ NULL, /* setDocumentLocator */ NULL, /* startDocument */ NULL, /* endDocument */ NULL, /* startElement */ NULL, /* endElement */ NULL, /* reference */ NULL, /* characters */ NULL, /* ignorableWhitespace */ NULL, /* processingInstruction */ NULL, /* comment */ NULL, /* xmlParserWarning */ NULL, /* xmlParserError */ NULL, /* xmlParserError */ NULL, /* getParameterEntity */ NULL, /* cdataBlock */ NULL, /* externalSubset */ 1, /* initialized */ NULL, /* private */ NULL, /* startElementNsSAX2Func */ NULL, /* endElementNsSAX2Func */ NULL /* xmlStructuredErrorFunc */ }; doc=htmlSAXParseFile(NULL,NULL,NULL,NULL); return; }
/tmp/ccCZWbiT.o: In function `main':
tracker-extract-xml.c
.text+0x4c): undefined reference to `htmlSAXParseFile'
collect2: ld returned 1 exit status
how can i solve this problem?
thanks in advance for your help.
- 01-13-2011 #2
You may have given the wrong path for your HTMLparser.h. Most systems nowadays use libxml2. Try using libxml2/libxml.
It's always a good idea when using a library for the first time to check up where it actually lives and where the header files are."I'm just a little old lady; don't try to dazzle me with jargon!"
- 01-13-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 3
thanks for your answer.
but unfortunately it still doesn't work
if i replace #include <libxml/HTMLparser.h> with #include <libxml2/libxml/HTMLparser.h> the compiler gives me the following message (and other similar ones):
/usr/local/include/libxml2/libxml/HTMLparser.h:15:31: error: libxml/xmlversion.h: No such file or directory
there's a problem with the position of file.h, but i have no idea how to deal with them.
the folder libxml2 is in /usr/include and in /usr/local/include. in both the libxml2 folders there's the folder libxml containing both HTMLparser.h and xmlversion.h. in HTMLparser.h all the include are like #include <libxml/file.h>
- 01-13-2011 #4
This is an ld error, not a gcc error. The error is because in your compiled program, the function htmlSAXParseFile cannot be found.
The reason is because you are not linking against the correct libraries. I've never used libxml, but the library is probably called libxml.so, so add this flag to your gcc command:
Code:-lxml
DISTRO=Arch
Registered Linux User #388732
- 01-13-2011 #5Just Joined!
- Join Date
- Jan 2011
- Posts
- 3
thank you very much..with the option -lxml2 it works


Reply With Quote