记录的比较粗糙,但是绝对可行的 一些小的瑕疵以后再解决吧 (android版本的过几天再贴,移植到android已经通过)

msys+mingw包下载:

http://sourceforge.net/projects/tdm-gcc/?source=dlp

http://sourceforge.net/projects/mingw/?source=dlp

http://sourceforge.net/projects/mingw/?source=dlp

安装方式:

参考:

http://wiki.videolan.org/Win32CompileMSYSNew

或者

http://blog.chinaunix.net/uid-26807463-id-3147631.html

glib依赖包下载(google):

zlib-1.2.8.tar.gz

libffi-3.0.12.tar.gz

libiconv-1.14.tar.gz

gettext-0.18.2.tar.gz

glib-2.34.3.tar.xz

,然后全部解压到C:\Msys\1.0\home\Administrator下,进入C:\Msys\1.0下 启动msys.bat 然后输入 cd home/Administrator/ (假设为Administrator用户)

编译zlib

cd zlib-1.2.8

make -f win32/Makefile.gcc

,然后 手动安装

cp -iv zlib1.dll /mingw/bin

cp -iv zconf.h zlib.h /mingw/include

cp -iv libz.a /mingw/lib

cp -iv libz.dll.a /mingw/lib/libz.dll.a

编译libffi-3.0.12

cd libffi-3.0.12

./configure --prefix=c:/MinGW && make && make install

编译libiconv-1.14

cd libiconv-1.14 && ./configure --prefix=c:/MinGW --without-libiconv-prefix --without-libintl-prefix --enable-relocatable && make && make install

cd ../

可能会出现下面的错误,这个是make install的时候出现的,和relocatable选项有关,可能是libiconv-1.14的一个bug,但是dll已经生成且已经安装到指定目录(头文件iconv.h得自己手动拷贝到C:\MinGW\include ^^),所以可以暂时忽略,如果要解决的话,可以参考一下链接:

http://git.yoctoproject.org/cgit.cgi/poky/plain/meta/recipes-support/libiconv/libiconv-1.14/add-relocatable-module.patch

http://savannah.gnu.org/users/mail6543210

https://lists.gnu.org/archive/html/bug-gnu-libiconv/2013-02/msg00004.html

http://lists.linuxtogo.org/pipermail/openembedded-core/2012-January/015887.html

==================error============================
libtool: link: gcc -g -O2 iconv.o iconv.res -o .libs/iconv.exe ../srclib/libicr
t.a c:/MinGW/lib/libiconv.dll.a -Lc:/MinGW/lib
../srclib/libicrt.a(progreloc.o): In function `prepare_relocate':
C:\Msys\1.0\home\Administrator\libiconv-1.14\srclib/progreloc.c:297: undefined r
eference to `compute_curr_prefix'
C:\Msys\1.0\home\Administrator\libiconv-1.14\srclib/progreloc.c:302: undefined r
eference to `set_relocation_prefix'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [install] Error 1
make[1]: Leaving directory `/home/Administrator/libiconv-1.14/src'
make: *** [install] Error 2
====================================================

编译gettext-0.18.2/gettext-runtime,为了获得 libintl-8.dll/libaprintf-0.dll/ngettext.exe

cd gettext-0.18.2/gettext-runtime

./configure --prefix=c:/MinGW --disable-java --enable-relocatable --without-libintl-prefix --with-libiconv-prefix=c:/MinGW && make && make install

cd ../

编译gettext-0.18.2

cd gettext-tools

./configure --prefix=c:/MinGW --disable-java --enable-relocatable --with-libintl-prefix=c:/MinGW --with-libiconv-prefix=c:/MinGW --disable-shared --with-libexpat-prefix=c:/MinGW --disable-openmp --enable-threads=win32 && make

可能会碰到错误, 没关系我们需要的exe已经好了, 直接cp src/*.exe /mingw/bin

编译glib-2.34.3

由于pkg-config在mingw里面默认没有装,而pkg-config又依赖glib库,这样就形成了循环依赖,我采用下面办法解决这个问题

export LIBFFI_CFLAGS='-I /mingw/lib/libffi-3.0.12/include'

export LIBFFI_LIBS=-lffi

./configure CFLAGS="-march=i486" --prefix=c:/mingw --with-threads=win32

make -j2

报错,如下

Creating library file: .libs/libgio-2.0.dll.a
CCLD gio-querymodules.exe
CCLD glib-compile-resources.exe
CCLD gsettings.exe
CCLD gdbus.exe
CCLD gresource.exe
make[4]: Leaving directory `/home/Administrator/glib-2.34.3/gio'
Making all in tests
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
make[4]: Entering directory `/home/Administrator/glib-2.34.3/gio/tests'
GEN test_resources.c
GEN test_resources2.c
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
GEN test_resources2.h
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
make all-recursive
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
XMLLINT not set and xmllint not found in path; skipping xml preprocessing.
make[5]: Entering directory `/home/Administrator/glib-2.34.3/gio/tests'
Making all in gdbus-object-manager-example
make[6]: Entering directory `/home/Administrator/glib-2.34.3/gio/tests/gdbus-obj
ect-manager-example'
GEN gdbus-example-objectmanager-generated.h
GEN gdbus-example-objectmanager-generated.c
/usr/bin/env: python2.5: No such file or directory
make[6]: *** [gdbus-example-objectmanager-generated.c] Error 127
make[6]: *** Waiting for unfinished jobs....
/usr/bin/env: python2.5: No such file or directory
make[6]: *** [gdbus-example-objectmanager-generated.h] Error 127
make[6]: Leaving directory `/home/Administrator/glib-2.34.3/gio/tests/gdbus-obje
ct-manager-example'
make[5]: *** [all-recursive] Error 1
make[5]: Leaving directory `/home/Administrator/glib-2.34.3/gio/tests'
make[4]: *** [all] Error 2
make[4]: Leaving directory `/home/Administrator/glib-2.34.3/gio/tests'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/Administrator/glib-2.34.3/gio'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/Administrator/glib-2.34.3/gio'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/Administrator/glib-2.34.3'
make: *** [all] Error 2

其实库已经编译完成 这是编译test模块的时候出错,估计是说缺少python工具,忽略该错误 ^^

make install完成安装

继续报错,如下:

make[3]: Entering directory `/home/Administrator/glib-2.34.3/gio/gdbus-2.0/codeg
en'
make[4]: Entering directory `/home/Administrator/glib-2.34.3/gio/gdbus-2.0/codeg
en'
/bin/mkdir -p 'c:/mingw/bin'
/bin/install -c gdbus-codegen 'c:/mingw/bin'
/bin/mkdir -p 'c:/mingw/lib/gdbus-2.0/codegen'
/bin/install -c -m 644 __init__.py codegen.py codegen_main.py codegen_docbook.p
y config.py dbustypes.py parser.py utils.py 'c:/mingw/lib/gdbus-2.0/codegen'
/bin/sh: line 19: python2.5: command not found
make[4]: *** [install-codegenPYTHON] Error 127
make[4]: Leaving directory `/home/Administrator/glib-2.34.3/gio/gdbus-2.0/codege
n'
make[3]: *** [install-am] Error 2
make[3]: Leaving directory `/home/Administrator/glib-2.34.3/gio/gdbus-2.0/codege
n'
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/home/Administrator/glib-2.34.3/gio'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/Administrator/glib-2.34.3/gio'
make: *** [install-recursive] Error 1

照样忽略即可。

测试

    #include <stdio.h>
#include <string.h>
#include <glib.h> #define TEST0(function) G_STMT_START {
if (!function())
g_print("test "#function" failed!\n");
}G_STMT_END int main(int agrc, char **argv)
{
g_print("Hello world!n");
TEST0(thread_test);
TEST0(main_loop_test);
TEST0(io_channel_test);
while(1);
} gpointer thr_func(gpointer data)
{
g_print("test-thread running, say: %s\n", data);
} gboolean thread_test(void)
{
return NULL == g_thread_new("test-thread", thr_func, "Hello")
? FALSE:TRUE;
} typedef struct _TimeBlock TimeBlock;
struct _TimeBlock {
gpointer data;
GMainLoop *loop;
}; gboolean time_func(gpointer data)
{
TimeBlock *tb = (TimeBlock *)data;
g_print("in time func, say: %sn", tb->data);
g_main_loop_quit(tb->loop);
return FALSE;
} gboolean main_loop_test(void)
{
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
TimeBlock tb = {"5s passe!", loop};
g_timeout_add(5*1000, time_func, &tb);
g_print("loop startn");
g_main_loop_run(loop);
g_print("loop endn");
g_main_loop_unref(loop); return TRUE;
} gboolean io_channel_test(void)
{
gboolean ret = FALSE;
GError *err = NULL;
gchar *tmp = g_strdup(g_get_prgname());
*strchr(tmp, '.') = 0;
gchar *filename = g_strdup_printf("%s%s", tmp, ".c");
g_free(tmp); GIOChannel *fio = g_io_channel_new_file(filename, "r", &err);
if (NULL != fio) {
gchar *buf; gsize buf_len;
GIOStatus fstatus = g_io_channel_read_to_end(fio, &buf, &buf_len, &err);
if (G_IO_STATUS_NORMAL == fstatus) {
g_print("read file:%s successed, file len:%d\n", filename, buf_len);
g_free(buf);
g_io_channel_unref(fio);
ret = TRUE;
} else {
g_print("read file:%s failed, err:%s\n", filename,
NULL == err? "UnKnow error!":err->message);
if (NULL != err)
g_error_free(err);
}
} else {
g_print("open file:%s failed, err:%sn", filename,
NULL == err? "UnKnow error!":err->message);
if (NULL != err)
g_error_free(err);
} g_free(filename); return ret;
}
//gcc glib-test.c -I /mingw/include/glib-2.0 -I /mingw/lib/glib-2.0/include -L /mingw/bin -lintl-8 -liconv-2 -lole32 -lglib-2.0 -o glib-test.exe

参考文章

http://mathslinux.org/?p=268#comment-1019

http://www.mingw.org/wiki/Bootstrapping_GLIB_with_MinGW

http://blog.sina.com.cn/s/blog_53825fe20100n9h8.html

完!

2013年7月

最新文章

  1. 如果你的SharePoint出现了,状态服务问题,InfoPath无法正常使用
  2. shell简单用法笔记(一)
  3. 链表 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
  4. BizTalk 中使用 WCF-OracleDB adapter
  5. Ibatis 测试出SQL
  6. tcp-client-c++
  7. Linux环境下的Nodejs
  8. SendMail
  9. C# 使用Sqlite 如何返回统计行数
  10. 移动端控制视频点击播放点击下一个视频时自动停止播放&amp;监听滑动溢出屏幕高度时停止播放
  11. Day4 Python基础之数据类型(三)
  12. django form 组件插件
  13. ASP.NET MVC5+EF6+EasyUI 后台管理系统--系统权限及操作指引
  14. Jenkins实现SVN+Maven+Java项目的持续集成
  15. HttpClient(4.5.x)正确的使用姿势
  16. c3p0的几种使用方式(原文地址: https://my.oschina.net/liangtee/blog/101047)
  17. DataInputStream FileInputStream 区别
  18. java基础-day9
  19. 2017-2018-2 20155224『网络对抗技术』Exp7:网络欺诈防范
  20. Vue的watch监听事件

热门文章

  1. MySQL☞create语句
  2. 第三十三篇 Python中关于OOP(面向对象)的常用术语
  3. Laxcus大数据管理系统2.0 (1) - 摘要和目录
  4. Fluentd插件使用方法
  5. [OpenCV]DMatch类和KeyPoints类:特征点匹配
  6. 测试理论- the conten of test plan
  7. ASP.NET CORE 2.0 文档中文正式版已经出来了
  8. 当网卡收到的包的目的地址是主机上另一个网卡的地址.arp总结
  9. windows下Memcached 架设及java应用(转)
  10. oracle视图就是封装了一条写好的sql语句 可通过视图修改表结构 ; oracle需要手动创建序列