vs2010 x64 下boost Python库编译 编译环境vs2010 window7 x64, boost 版本1.47.0 Python 版本2.7.2 1、编译x64 位boost Python 需要卸载Python32位安装Python 64位, 编译x32位boost Python 需要卸载Python64位安装Python64位 编译boostPython 的debug 和release 都需要只依赖Python安装目录下的release版pyhon 的lib,不需要单独下载Python 的源码自己编译出Python Debug 和Python Release。 < xmlnamespace prefix ="o" ns ="urn:schemas-microsoft-com:office:office" /> 2、自己编译的Python 存在这样一个问题: Python Release 编译后生成了 python.exe、python27.dll 、python27.lib Python Debug 编译后生成了python_d.exe、 python27_d.dll 、python27_d.lib, 如图: < xmlnamespace prefix ="v" ns ="urn:schemas-microsoft-com:vml" /> 编译过程中发现,用自己生成的python release 编译 boost python 的release版本,生成和运行都没有问题,但是用自己生成的 python debug 编译 boost python的debug版本,链接器在链接python_d.lib 的同时也链接了 python.lib ,能顺利生成debug版的boost python的lib。当自己开发的程序调用了boost python lib库运行debug版时,会同时加载 python_d.dll 和 python.dll 这样就会造成程序运行初始化python( Py_Initialize() )时崩溃这个问题不知道是什么原因产生的。
3、所以在编译boost python 时,不需要下载python 的源码自己编译,只需要下载python 的安装包,安装相应的python 版本。也可以自己下载python 的源码编译出python 的release 版,编译boostPython 的debug 和release 都只依赖这个release版pyhon 的lib。
4、python 安装后例如在 C:\python27,python.exe在c:\python27 目录下, python27.lib 在C:\Python27\libs 目录下, python27.dll 在系统的system32 目录下。
5、boost python 编译过程 (1)、安装好Python , 下载boost 的源码,解压到一个目录下,例如d:\ D:\boost_1_47_0 (2)、按照网上很多人说的,首先编译boost 的编译器 bjam.exe, bjam的源码已经被包含在boost 的源码中, 在D:\boost_1_47_0\tools\build\v2 目录下有个 bootstrap.bat , 运行vs 2010 x64 的命令提示符工具,如图: ![]()
执行命令 : cd /D D:\boost_1_47_0\tools\build\v2\ 将命令提示符窗口定位到 D:\boost_1_47_0\tools\build\v2 目录下, ![]()
执行命令: bootstrap.bat 开始 bjam 的编译,
![]()
编译bjam完成后如上图所示 在 D:\boost_1_47_0\tools\build\v2\engine\bin.ntx86_64 目录下找到 bjam.exe , (3)、修改bjam 的配置文件,在D:\boost_1_47_0\tools\build\v2 用文本编辑器打开user-config.jam 这个文件, 修改其中的设置,将 # Configure specific msvc version (searched for in standard locations and PATH). # using msvc : 8.0 ; 改为(因为这里用的是vs 2010): # Configure specific msvc version (searched for in standard locations and PATH). using msvc : 10.0 ; 将: # --------------------- # Python configuration. # ---------------------
# Configure specific Python version. # using python : 3.1 : /usr/bin/python3 : /usr/include/python3.1 : /usr/lib ; 改为(python2.7 的安装目录和python 版本设置)设置python 的目录和版本等信息: # --------------------- # Python configuration. # ---------------------
# Configure specific Python version. using python : 2.7 : C:\\Python27 : C:\\Python27\\include : C:\\Python27\\libs ;
(4)、将刚才的bjam.exe 拷贝到 D:\boost_1_47_0\ 下,准备boost 库的编译。 将命令提示符定位到 D:\boost_1_47_0\ 下 执行 bjam 编译命令 一下这两种智能 只能编译出静态库,不能编译出动态库 bjam --with-python --build-type=complete 理论上能生成所有可能版本的lib (debug 动态库版,debug静态库版,release 动态库版,release静态库版,debug但线程版,debug多线程版, release单线程版,release多线程版.. ) 或者 bjam --with-python --toolset=msvc-10.0 --prefix=d:\boost install 但是在编译时发现 编译boost python动态库版时会报python 的函数无法解析的外部符号,能成功编译boost python静态库的版本。
能正确生成 动态库版本的命令写法: x64 debug bjam --with-python --prefix=d:\boost stage toolset=msvc-10.0 variant=debug link=shared address-model=64 threading=multi runtime-link=shared install
x64 release bjam --with-python --prefix=d:\boost stage toolset=msvc-10.0 variant=release link=shared address-model=64 threading=multi runtime-link=shared install
貌似是因为64位寻址和32 位寻址的不同,所以不加address-model=64 的话会造成编译动态库版boost python 出现python 无法解析的外部符号的问题。
6、 在使用boost python 和python 生成自己的应用程序, 若 不把 C:\Python27 目录下的lib 文件夹拷贝到自己的应用程序所在的目录,则生成的程序不能在没有安装python 的机器上正确运行python 的初始化函数。 拷贝后如下图: ![]()
即 依赖python的程序必须要有 python的lib
参考了网上的一篇文章 http://china.ygw.blog.163.com/blog/static/68719746201152485054104/ |
|