glib windows下编译
记录的比较粗糙,但是绝对可行的 一些小的瑕疵以后再解决吧 (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月
glib windows下编译的更多相关文章
- [转] Windows下编译OpenSSL
简述 OpenSSL是一个开源的第三方库,它实现了SSL(Secure SocketLayer)和TLS(Transport Layer Security)协议,被广泛企业应用所采用.对于一般的开发人 ...
- Windows下编译objective-C
Windows下编译objective-C 2011-08-31 14:32 630人阅读 评论(0) 收藏 举报 windowscocoa工具objective clibraryxcode 目录 ...
- 在Windows下编译FFmpeg详细说明
MinGW:一个可自由使用和自由发布的Windows特定头文件和使用GNC工具集导入库的集合,允许你生成本地的Windows程序而不需要第三方C运行时 MinGW,即 Minimalist GNU F ...
- 如何在WINDOWS下编译BOOST C++库 .
如何在WINDOWS下编译BOOST C++库 cheungmine 2008-6-25 写出来,怕自己以后忘记了,也为初学者参考.使用VC8.0和boost1.35.0. 1)下载boost ...
- 在Windows下编译OpenSSL(VS2005和VC6)
需要说明的是请一定安装openssl-0.9.8a . openssl-1.0.0我没有编译成功. 如何在Windows下编译OpenSSL (Vs2005使用Vc8的cl编译器)1.安装Activ ...
- windows下编译java源文件的编码错误
import java.util.Arrays;public class ArrayAsAReference{ public static void main(String[] args) { int ...
- Windows下编译SDL
Windows下编译SDL的理由我就不多说了,无论用VS来编译或调试SDL库都是很方便的.而且SDL源代码中也包含了VC工程,你所要做的只是解压VC工程,进行适当的配置,然后编译.调试. 编译SDL大 ...
- Windows下编译安装 FFmpeg
在Linux/Mac下编译 ffmpeg是非常方便的.但要在 Windows下编译 ffmpeg还真要花点时间.以下就是在 Windowns下编译ffmpeg的步骤: 一.安装Cygwin 在wind ...
- windows下编译php7图形库php_ui.dll
CSDN博客 具有图形化编程才有意思,这几天看到了php ui 图形扩展,只是现在只能下载php 7.1的 本次教程编译php7.2.6的 php ui 要是linux下编译起来比较简单 但是 win ...
随机推荐
- LeetCode 876——链表的中间结点
1. 题目 给定一个带有头结点 head 的非空单链表,返回链表的中间结点. 如果有两个中间结点,则返回第二个中间结点. 示例 1: 输入:[1,2,3,4,5] 输出:此列表中的结点 3 (序列化形 ...
- 深度可分卷积(Depthwise Separable Conv.)计算量分析
上次读到深度可分卷积还是去年暑假,各种细节都有些忘了.记录一下,特别是计算量的分析过程. 1. 标准卷积和深度可分卷积 标准卷积(MobileNet论文中称为Standard Convolution, ...
- C#非托管跨线程委托调试
使用C#调用mingw的so文件,拿视频数据回wpf的界面进行显示,注册了回调函数.C++在调用回调函数时遇到了委托被回收的问题,提示:“类型的已垃圾回收委托进行了回调.这可能会导致应用程序崩溃.损坏 ...
- NOIP 2009 靶形数独(DLX)
小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z 博士请教,Z 博士拿出了他最近发明的“靶形数独”,作 ...
- C#程序中SQL语句作为函数参数形式问题
今天遇到一个神奇现象,目前正在写一个Demo,人事管理系统,首先肯定是初始化主页面,在初始化时,需要声明一个登陆窗体,但是当我在登陆窗体中填入登入名称和密码时直接就登陆成功了,但是发现我的status ...
- PTA实验报告 数组
(第二张代码均为英红的代码) 题目1:题目名称:数组元素循环右移问题 1. 本题PTA提交列表 2. 设计思路(包括流程图) 将数组内每个位置移动,第2个放第一个,第三个放第二个,以此类推.使用两个循 ...
- python practive
定义新的操作指令,并将其组合到一起以便能够做一些有意义的事情,这就是编程工作的核心和灵魂. 计算型思维: 1,强调概念化,而非程序化.计算机科学不是计算机程序.像计算机科学家一样的思考,不只是说要编程 ...
- php 将数组存入cookie
最近在做一个购物车的功能,需要将商品的ID和商品数量存入cookie,实际上,cookie是不能存数组的,因此需要用到序列化函数serialize() 函数解释: serialize()就是将PHP中 ...
- wait_event_interruptible_timeout
最近一套方案涉及到内核线程之间的同步,用到了函数wait_event_interruptible_timeout函数,大致是这样: A:是一个后台的线程,平常没事就睡觉,有时被唤醒,或者每5分钟醒一次 ...
- hdu 3486 Interviewe (RMQ+二分)
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...