這幾天在學習libxml。 今天嘗試安裝並編譯了一下。
安裝
安裝很簡單。 兩條命令:
(1) sudo apt-get install libxml++2.6-dev
(2) sudo apt-get install libxml++2.6-doc
編譯
安裝成功後寫了一個hello world程序做了下測試
【源代碼】
#include <iostream>
#include <string>
#include "libxml++/libxml++.h"
using namespace std;
int main()
{
string file_name = "example.xml";
xmlpp::DomParser parser;
parser.parse_file( file_name );
if (parser)
{
cout << "open " << file_name << endl;
}
else
{
cout << "cannot open " << file_name << endl;
}
return 0;
}
然後再寫個Makefile
xml:xml.o
g++ -o xml xml.o $(INCLUDES) $(LIBS)
xml.o:xml.cpp
g++ $(INCLUDES) -c $^
INCLUDES = -I/usr/local/include /
-I/usr/include/glibmm-2.4 /
-I/usr/lib/glibmm-2.4/include /
-I/usr/include/libxml++-2.6 /
-I/usr/lib/libxml++-2.6/include /
-I/usr/include/glib-2.0 /
-I/usr/lib/glib-2.0/include
LIBS = -L/usr/lib /
-L/usr/local/lib /
-lxml++-2.6
libxml++ 庫依賴glibmm 和glib 所以需要把這兩個lib也include上