Search code examples
cmacoslibxml2

Compiling or using libxml using C on OSX


If I want to compile a c source file that uses libxml, how do I setup libxml on mac osx so that my source file will just compile correctly and be ready to run?

I have been using XCode until now, but have switched to TextMate & Terminal, Do I need to create a makefile if I want to use libxml or how will this work?

Thanks

EDIT:

I use the current imports

#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

Solution

  • The headers for the libxml2 distribution on 10.6 resides within /usr/include/libxml2/. Unfortunately, just the /usr/include part is within the system default header search path. Thus, you need to explicitly include it on the command line (or have your #includes also include the additional libxml2 folder). The library itself resides at the usual /usr/lib/libxml2.dylib.

    Thus, use the following command to compile your program:

    gcc source.c -I/usr/include/libxml2 -lxml2 -o output