- 前提条件:MINGW32環境、MSYS環境構築済み
xmlsoft.org (libxml 関連のサイト)からリンクをたどって、ソースファイルのtarball を落としてくる。
とりあえず今回落としたファイルのバージョンは2.6.30 (libxml2-sources-2.6.30.tar.gz)
- 適当なディレクトリに展開し、MSYS環境下でそのディレクトリに入る。
- 何はなくともconfigure
mingw関連は /mingw 以下に入れてあるので、 --prefix=/mingw/local でいいかな。
その他、いらないものをそぎ落とす。
--without-docbook --without-ftp --without-html --without-http --without-iconv
--without-legacy --without-python --without-threads --without-zlib
(左から、DOCBOOKサポート、FTPサポート、HTMLサポート、HTTPサポート、libiconv (文字コード変換ライブラリ)サポート、deprecated APIサポート、pythonサポート、multi threadサポート、zlib使用
そして、make install (make testはなかった..)
エラーは出ず、makeは完了したようです :D
では、練習も兼ねて、テスト。
% cat Makefile
## Makefile
##
## * MSYS環境下で make コマンドを実行すること。
XML2_CONFIG=/mingw/local/bin/xml2-config
CFLAGS += `$(XML2_CONFIG) --cflags`
LDFLAGS += `$(XML2_CONFIG) --libs`
SRC=main.c
OBJ=$(SRC:.c=.o)
EXEC=test.exe
all: $(EXEC)
clean:
$(RM) $(OBJ) $(EXEC)
$(EXEC): $(OBJ)
$(CC) -o $(EXEC) $(OBJ) $(LDFLAGS)
% cat main.c
/*!
* \file
* \brief libxml2 のパースのテストコード
*
* 元ねたは、libxmlのサイト
* http://xmlsoft.org/examples/parse3.c
*/
#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
/* XML文書 */
static const char* document = "<root><test attr='hoge'>content</test></root>";
/*!
* \brief パース例
*
* パースして開放するだけ。
*
* \param[in] content XML文書
* \param[in] length \p contentの文字列長
*/
static void
parse_example(
const char* content,
size_t length
)
{
xmlDocPtr doc; /* document ルート */
doc = xmlReadMemory(
content,
length,
"http://floralcompany.jp/", /* base URL */
NULL, /* encoding */
0 /* options */
);
if ( NULL == doc ) {
fprintf( stderr, "failed to parse document\n");
return;
}
xmlFreeDoc(doc);
}
int main()
{
/* 英文コメントがついている行はサンプルからほぼそのままコピー */
/*
* this initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION;
parse_example(document, strlen(document));
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
/*
* this is to debug memory for regression tests
*/
xmlMemoryDump();
return 0;
}
% make
% ln /mingw/local/bin/libxml2-2.dll # これをやっておかないと、dllを探しに行けなかった。
% ./test.exe
まぁ、何も出力されてないけど、きっとうまくいってるのであろう..





コメントする