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>
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
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
You can also xml2-config to get the compilation flags to use.
kjp@vbox:~/Dev/ScratchDir$ xml2-config --cflags --libs
-I/usr/include/libxml2
-lxml2
kjp@vbox:~/Dev/ScratchDir$
I vote for Kjp's answer with a simple modification. How about include the xml2-config to the gcc command itself -
g++ -o bin_name `xml2-config --cflags` main.c `xml2-config --libs`
This should work even if libxml is not installed on the default location OR the flag name is changed (in future).
CHEERS!
精彩评论