使用VS2010编译glib库

使用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%;
set LIB=c:\gtk_compilation\vs10\win32\lib;%LIB%
set INCLUDE=c:\gtk_compilation\vs10\wn32\include;%INCLUDE%
3、在VS 2010命令行编译zlib库

ZLib

(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

4、 在VS 2010命令行编译gettext库

gettext-runtime

(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.

  1. 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.

  2. 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.

  3. Replace the intl.def in $(srcroot)\gettext-runtime\intl with this, as some needed symbols are missed from the .def file.

  4. Run from your VS2008 or 2010 (or Windows SDK) 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, and regenerate the NMake makefiles if necessary.
  5. Run "nmake", followed by "nmake install"
ps:下载  gettext-0.18-runtime sources for VS10 or  gettext-0.18-runtime sources for VS9 的网址:winkde.org 不知道什么原因打不开,
所以我就没有按上面的步骤编译gettext库,而是直接下载gettext.exe文件运行安装的gettext库。

5、在VS2010命令行编译pcre库

PCRE (Optional for GLib)

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.

  1. Grab the latest stable PCRE sources from here-note that you need at least 8.32 to build the latest stable versions of GLib.

  2. 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.

  3. Run "nmake", followed by "nmake install"
6、在mozilla-build MSYS bash prompt环境编译libffi库

libffi

This library is needed to build GLib (specifically GObject) and gobject-introspection, for foreign function interface usage.

  1. 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.

  2. Grab the latest libffi 3.0.10 (or later) sources from here. Unpack it somewhere.

  3. 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]
  4. Run "make";"make install". If "make install" fails for some reason, do the following:
    • copy ffi.h and ffitarget.h from $(srcroot)\i686-pc-mingw32\include (Win32) or $(srcroot)\x86_64-w64-mingw32\include to c:\gtk_compilation\$(VS_VER)\$(Platform)\include
    • copy libffi_conveneince.lib from $(srcroot)\i686-pc-mingw32\.libs (Win32) or $(srcroot)\x86_64-w64-mingw32\.libs to c:\gtk_compilation\$(VS_VER)\$(Platform)\lib\libffi.lib (yes, rename the .lib file!)
7、在VS2010环境编译glib 库,我使用的版本为(glib-2.40.2)
    This package requires gettext-runtime, ZLib and libFFI (libFFI is required for GLib 2.29.x or later only). PCRE is optionally required-it is included in the GLib tarball.

    编译步骤如下:
    1、 Grab the latest stable/unstable tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\.
    2、 Open the Visual C+ solution file in GLib's $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS2010). If you like to use your own copy of PCRE, use the configurations with the _ExtPCRE suffix.
    3、编译过程遇到的问题如下:

    (1):
    错误:
        error C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失c:\mmx_workspace\gstreamer\glib-2.40.2\glib\gmain.c5294
    解决方法:
        将本机系统区域语言设置成英语,即依次点击(控制面板->时钟、语言和区域->区域和语言->管理->区域和语言设置->当前系统区域设置英       语),然后重启一下系统就可以了,如下图:
使用VS2010编译glib库_第1张图片

    (2)pcre函数等错误,设置预编译宏PCRE_STATIC

你可能感兴趣的:(计算机)