下载 mingw-w64 , 下载 msys。
资源包常用下载地址:(也可直接百度 “index of glib”)
http://mirrors.ustc.edu.cn/gnu
http://ftp.gnome.org/pub/gnome/sources/glib/
http://distfiles.macports.org/libxml2/
http://ftp.exim.llorien.org/pcre/
http://mirrors.ibiblio.org/gnu/ftp/gnu/ncurses/
一、编译glib-2.0
参考文章:
https://www.douban.com/note/216473248/
http://blog.163.com/wangxuefan1220@126/blog/static/8821147201231904427205/
- msys命令行中输入
mount D:/mingw-w64/mingw64 /mingw
来映射路径。 编辑 msys 启动宏定义: msys/etc/profile
# 所有的变量都定义在/etc/profile里,在启动mintty的时候自动加载。 export PATH=/mingw/bin:/mingw/x86_64-w64-mingw32/bin:/mingw/libexec/gcc/x86_64-w64-mingw32/7.2.0:/usr/local/bin:/usr/bin:$PATH export C_INCLUDE_PATH=/mingw/include:/mingw/x86_64-w64-mingw32/include:/usr/local/include # C++头文件顺序需要在C头文件前 export CPLUS_INCLUDE_PATH=/mingw/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++:$C_INCLUDE_PATH export LIBRARY_PATH=/mingw/lib:/mingw/x86_64-w64-mingw32/lib:/mingw/opt/lib:usr/local/lib:/mingw/lib/gcc/x86_64-w64-mingw32/7.2.0 export LDFLAGS="-L/usr/local/lib -L/mingw/lib -L/mingw/x86_64-w64-mingw32/lib -L/mingw/opt/lib" ##定义pkg-config的地址和config路径。 export PKG_CONFIG=/bin/pkg-config.exe export PKG_CONFIG_PATH=/mingw/lib/pkgconfig export BUILD=x86_64-w64-mingw32 export HOST=x86_64-w64-mingw32 export TARGET=x86_64-w64-mingw32 export PREFIX=/mingw export CC=gcc export CXX=c++
- 安装依赖库(安装之前搜索是否已经存在)(注:也可尝试使用 http://win32builder.gnome.org/ 内的完整包)
1)../pkg-config-0.29.2/configure --prefix=$PREFIX --with-internal-glib
参数 –with-internal-glib 指定使用内部 glib (注:也可直接使用 msys/bin 下的 pkg-config, 无需编译更改 PKG_CONFIG 宏即可)
2) zlib-1.2.11
copy win32\makefile.gcc makefile.gcc
mingw32-make -f makefile.gcc
3) pthreads-w32-2-9-1-release
make clean GC-static
cp libpthreadGC2.a /mingw/lib
cp pthread.h sched.h /mingw/include
4)../libxml2-2.9.7/configure --build=$BUILD --target=$TARGET --prefix=$PREFIX CPPFLAGS="-I/usr/local/include -DLIBXML_STATIC" --without-python LDFLAGS="-L/usr/local/lib -L/mingw/lib -L/mingw/x86_64-w64-mingw32/lib -L/mingw/opt/lib -lws2_32 -lz -lwsock32 -lregex"
5)../libiconv-1.15/configure --prefix=$PREFIX --enable-static --disable-shared
(注:也可以使用 mingw-w64 自带的 libiconv.a,在 /mingw/bin/pkgconfig 下编辑 libiconv.pc 来给 pkg-config 提供编译参数与库位置。)
6)libffi-3.2.1 编译时 win32.s 文件内指令错误,初步认为是64bit 和 32bit 问题。 直接编写.pc文件使用 /mingw/opt/lib 下的
7) pcre-8.41
../pcre-8.41/configure --prefix=$PREFIX --enable-utf8 --enable-unicode-properties
8)pixman-0.34.0
9) gettext-0.19.8.1 (注:也可直接使用 msys/bin 下的 gettext)
../gettext-0.19.8.1/configure --prefix=$PREFIX --enable-shared --enable-static --enable-threads=win32 --disable-java --disable-csharp --disable-openmp CPPFLAGS="-I/mingw/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++ -I/mingw/include -I/mingw/x86_64-w64-mingw32/include -I/usr/local/include -DLIBXML_STATIC"
问题:undefined reference to _imp__xmlFree
解决:在相应文件头部加上以下代码
(以及configure CPPFLAGS参数 -DLIBXML_STATIC)
#if !defined(LIBXML_STATIC)
#define XMLPUBFUN __declspec(dllexport)
#define XMLPUBVAR __declspec(dllexport)
#else
#define XMLPUBFUN
#if !defined(LIBXML_STATIC)
#define XMLPUBVAR __declspec(dllimport) extern
#else
#define XMLPUBVAR extern
#endif
#endif
#define XMLCALL __cdecl
#define XMLCDECL __cdecl
#if !defined _REENTRANT
#define _REENTRANT
#endif
#endif
10) glib-2.55.0
../glib-2.55.0/configure --prefix=$PREFIX --enable-static --disable-shared --with-threads=win32
make & make install
二、按照方法一编译安装库,不仅编译过程复杂,且编译完成后,可能还不能用。可以直接到 http://win32builder.gnome.org/ 下载完整包解压进去,配置 msys/etc/profile 启动的pkg-cpnfig相关变量即可。
待续