Saturday, May 5, 2012

Issues you may encounter when compiling LibXML2

I did not encounter this error before, but on my second compilation months after, I got a weird error saying:
testThreads.c:110:6: error: conversion to non-scalar type requested

So wondering what is wrong, I immediately opened Google and looked on how to resolve it. I found it pretty fast.

pthread_t under Windows is a structure, so the operations performed in testThreads.c on pthread_t are invalid.

I found the fix here, but in case it gets deleted, I am also posting it here.

Open testThreads.c and scroll down to line 110. Change this line:
tid[i] = (pthread_t) -1;
to this
tid[i].p= NULL;

After this, re-issue `make` and all should be good to go.

An important thing to note, is that linking to libxml2.a, or -lxml2 when fed to GCC automatically produces a statically linked executable to libxml2 IF it was compiled from withing the win32 folder and using makefile.mingw, increasing your executable size by at least 900KB.

While static linking makes redistributing your application easier, it also increases the size of the executable unnecessarily. In order to compile your application without statically linking to libxml2 and assuming you have libxml2-2.dll and libxml2.dll.a, you need to change
-lxml2 to -lxml2.dll 

After that, you will need to redistribute your application with the libxml2-2.dll.

Shared library under windows seems to broken for now, so I wouldn't count on it at this point.

No comments:

Post a Comment