1

Ok Peeps. I'm struggling with the basics here.

the file structure is:

./Makefile
./main.c
./libxml2-2.0.0/parser.c
./libxml2-2.0.0/parser.h

./libxml2-2.0.0/parser.h:

...
xmlDocPtr   xmlParseDoc     (xmlChar *cur);
...

./libxml2-2.0.0/parser.c:

...
xmlDocPtr
xmlParseDoc(xmlChar *cur) {
    return(xmlSAXParseDoc(NULL, cur, 0));
}
...

part of my code is:

main.c:

#include <curl/curl.h>
#include <parser.h>
#include <tree.h>

struct string {
  char *ptr;
  size_t len;
};
void extractXML(struct string *s)
{
    xmlDocPtr doc;
    doc = xmlParseDoc( (xmlChar *) s->ptr);
}
int main(void){..}

Makefile:

CC=gcc
LIBS = -lcurl
MyProgram: main.c
    $(CC) $?  $(LIBS) -Ilibxml2-2.0.0 -o $@

ERROR:

In function `extractXML':
main.c:(.text+0xbf): undefined reference to `xmlParseDoc'

So the library is included, other libxml and parser.h elements are being used fine, but xmlParseDoc I can't use. How to solve it?

Makan
  • 2,508
  • 4
  • 24
  • 39
  • 2
    Does not look like you compile or link parser.c. – Yunnosch Dec 20 '17 at 17:39
  • The `-I` option simply adds that path to the list of paths to search for header files. As mentioned you still need to build and link in parser.c – yano Dec 20 '17 at 17:41
  • 1
    this looks pretty similar to what you're trying to do: http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ – yano Dec 20 '17 at 17:48
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – n. m. could be an AI Dec 20 '17 at 18:00
  • So I just built the libxml. How do I link it here? – Makan Dec 23 '17 at 02:05
  • 1
    I just tried -L. and -lm as I saw online, to refer to the libraries folder.. but the problem persists – Makan Dec 23 '17 at 02:11

0 Answers0