1. 编译chmlib
源代码带了Visual Studio的工程文件,直接编译,可得到静态库libchm.lib
将libchm.lib改名为chm.lib
2. 编译pychm
1) 执行python-build-env.bat (具体说明见上次blog文章),其内容如下@echo off
set VC_TOOLKIT_DIR=d:\Program Files\Microsoft Visual C++ Toolkit 2003\
call "%VC_TOOLKIT_DIR%\vcvars32.bat"
set DISTUTILS_USE_SDK=1
set MSSDK=d:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\
rem set MSSDK=e:\msys\1.0.11\mingw\
set include=%MSSDK%include;%include%
set lib=%MSSDK%lib;%lib%
echo "Now you can continue with 'python setup.py build/install'"
2) 将chmlib的目录加入include和lib环境变量
set include=e:\python\pychm-0.8.4\chmlib\src;%include%
set lib=e:\python\pychm-0.8.4\chmlib\src\release;%lib%
2) VC没有inttypes.h和strings.h,我也没有找到其它定义了uint8_t等类型和strcasecmp等函数的头文件,所以修改extra.c的如下两行
#include修改为:
#include
3) 修改distutils\msvccompiler.py中MSVCCompiler.initialize()函数
#if !defined(_MSC_VER)
#include
#include
#else
/* MSVC's C compiler doesn't support `inline' */
#define inline
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned uint32_t;
typedef unsigned long long uint64_t;
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif
将
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']改为
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO', '/NODEFAULTLIB:libc']
否则libc和msvcrt里面的一些函数会打架
4) python setup.py install
搞定