使用VS2010编译glib库过程
note:参考网址:https://wiki.gnome.org/Projects/GTK%2B/Win32/MSVCCompilationOfGTKStack
1、安装VS2010集成开发环境
2、为整个处理过程建立一个工作目录
Set up a working folder for this entire process, such as gtk_compilation, as follows, where Platform is Win32(32-bit) or x64(64-bit, x86-64), and $(VS_VER) is vs9 (Visual C++ 2008) or vs10 (Visual C++ 2010):
mkdir c:\gtk_compilation\vs10\win32 mkdir c:\gtk_compilation\vs10\win32\bin mkdir c:\gtk_compilation\vs10\win32\include mkdir c:\gtk_compilation\vs10\win32\lib
It is recommended in the Visual Studio Command prompts that you do the following, which is useful for building CMake items at least:
进入VS2010命令行,即点击(开始->所有程序->Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio 命令提示(2010)),执行如下命令,设置环境变量:
set PATH=c:\gtk_compilation\vs10\win32\bin;%PATH%;3、在VS 2010命令行编译zlib库set LIB=c:\gtk_compilation\vs10\win32\lib;%LIB% set INCLUDE=c:\gtk_compilation\vs10\wn32\include;%INCLUDE%
(Required directly by GIO, Cairo and GDK-Pixbuf)
Download the latest ZLib source package (1.2.5 at this time of writing) from the ZLib homepage, and unpack the zip/tarball file to some location.
Decide first whether you are compiling Release or Debug-if you are compiling as debug, find the line in win32/makefile.msc:
CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)
and change it to
CFLAGS = -nologo -MDd -W3 -Od -Zi -Fd"zlib" $(LOC)
In the Visual C++ command prompt, run the following:
cd $(the_folder_where_zlib_was_unpacked) nmake -f win32/makefile.msc LOC="-DASMV -DASMINF" OBJA="inffas32.obj match686.obj" /*this is for 32-bit*/ nmake -f win32/Makefile.msc AS=ml64 LOC="-I. -I.\win32 -DASMV -DASMINF" OBJA="inffasx64.obj gvmat64.obj inffas8664.obj" /*this is for x86-64, run this command as a single line*/
The compilation of ZLib should be done in a minute at this point. For convenience reasons, you should also copy the resulting zdll.lib as zlib1.lib [or zlib1d.lib if compiling as debug if building for glib-2.42.2 or earlier](but please do not copy the DLL file as such!) Copy the resulting files as follows:
-Copy zlib.h and zconf.h in ZLib's $(srcroot) to c:\gtk_compilation\$(VS_VER)\$(Platform)\include
-Copy zdll.lib and zlib1.lib in ZLib's $(srcroot) to c:\gtk_compilation\$(VS_VER)\$(Platform)\lib
-Copy zlib1.dll in ZLib's $(srcroot) to c:\gtk_compilation\$(VS_VER)\$(Platform)\bin
(This is required for all components of the GTK+ stack)
This is one of the harder ones to build with Visual C++, but it is possible with a non-official package.
Make sure you have CMake installed, and it is accessible from your VS2008 or VS2010 command line! If you do not have CMake installed, get the latest stable Win32 binary from here, and navigate on the page to "Resources" -> "Download". This is also needed for compiling PCRE for those who want to.
Grab gettext-0.18-runtime sources for VS9 or gettext-0.18-runtime sources for VS10 from the WinKDE project. Unpack the file that you have just downloaded into some location.
Replace the intl.def in $(srcroot)\gettext-runtime\intl with this, as some needed symbols are missed from the .def file.
This is optional for GLib-but people may want to do this if they want to have a PCRE DLL where they can used in multiple programs. You need to have CMake to compile this (please see the gettext-runtime section on this). Note that for the GLib regex tests to pass, you need to build the PCRE that is bundled by GLib.
Grab the latest stable PCRE sources from here-note that you need at least 8.32 to build the latest stable versions of GLib.
Run from your Visual Studio) command line: cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=c:\gtk_compilation\$(VS_VER)\$(Platform). This is going to take a while-after it is done, use cmake-gui to verify that the entries (the CMAKE_BUILD_TYPE, which determines a "Debug" or "Release" build, and CMAKE_INSTALL_PREFIX) are correct. Also, within the CMake GUI, you need to ensure that the UNICODE and UTF-8 options are selected, and that BUILD_SHARED_LIBS is selected. If LibBZ2 and LibReadlineis not available on your system, please ensure that PCRE_SUPPORT_LIBBZ2 and PCRE_SUPPORT_LIBREADLINE are unchecked (if these options are displayed)--this part is optional as this only ensures the successful builds of the PCRE command-line tools. Regenerate the NMake makefiles.
This library is needed to build GLib (specifically GObject) and gobject-introspection, for foreign function interface usage.
You will need to get the mozilla-build package from here. It's a large package, but it is the Mozilla people who managed to write the assembly code that can be built with VS so that people can make use of it everyday in Firefox 4.x+. Install the package at its suggested location-most probably c:\mozilla-build.
Grab the latest libffi 3.0.10 (or later) sources from here. Unpack it somewhere.
Open a mozilla-build MSYS bash prompt by using one of the start-*.bat files under c:\mozilla-build (or whereever it is installed to)-pick the one that suits your environment the best. For people using the Windows SDK to compile 64-bit apps, you may need run manually from your Windows SDK command prompt:
set MOZBUILDDIR=c:\mozilla-build\ set MOZILLABUILD=%MOZBUILDDIR% set MOZ_TOOLS=%MOZBUILDDIR%moztools-x64 start /d "%USERPROFILE%" "" "%MOZILLABUILD%"\msys\bin\bash --login -i
Go to the $(srcroot) of libffi-3.0.10, and run one of the following: (Note: run the configure line as is, except in c:/gtk_compilation/$(VS_VER)/$(Platform), as noted earlier!)
./configure CC="$(pwd)/msvcc.sh -m64" LD=link CPP='cl -nologo -EP' CFLAGS='-O2' --build=x86_64-w64-mingw32 --prefix=c:/gtk_compilation/$(VS_VER)/$(Platform) [for x64] ./configure CC=$(pwd)/msvcc.sh LD=link CPP='cl -nologo -EP' CFLAGS='-O2' --build=i686-pc-mingw32 --prefix=c:/gtk_compilation/$(VS_VER)/$(Platform) [for Win32]