Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling or using libxml using C on OSX

Tags:

c

macos

libxml2

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>
like image 244
some_id Avatar asked Dec 17 '22 15:12

some_id


2 Answers

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
like image 89
mbauman Avatar answered Dec 24 '22 15:12

mbauman


No setup required. Add -lxml2 to your link command.

If you just have a simple single-source file "project":

gcc yourSourceFile.c -I/usr/include/libxml2 -lxml2 -o executableProgram
like image 23
Stephen Canon Avatar answered Dec 24 '22 14:12

Stephen Canon