分享

vs2010 x64 下 boost Python 编译

 londonKu 2012-03-28

vs2010 x64 boost Python库编译

编译环境vs2010 window7 x64

boost 版本1.47.0

Python 版本2.7.2

1、编译x64 boost Python 需要卸载Python32位安装Python 64位,

       编译x32boost Python 需要卸载Python64位安装Python64

       编译boostPython debug release 都需要只依赖Python安装目录下的releasepyhon lib,不需要单独下载Python 的源码自己编译出Python Debug Python Release

< xmlnamespace prefix ="o" ns ="urn:schemas-microsoft-com:office:office" /> 

2、自己编译的Python 存在这样一个问题:

Python Release 编译后生成了 python.exepython27.dll python27.lib

Python Debug 编译后生成了python_d.exe python27_d.dll python27_d.lib 如图:

vs2010 x64 下 boost Python 编译 - zhongzhe - 我的博客

< xmlnamespace prefix ="v" ns ="urn:schemas-microsoft-com:vml" />

编译过程中发现,用自己生成的python release 编译 boost python release版本,生成和运行都没有问题,但是用自己生成的 python debug 编译 boost pythondebug版本,链接器在链接python_d.lib 的同时也链接了 python.lib ,能顺利生成debug版的boost pythonlib。当自己开发的程序调用了boost python  lib库运行debug版时,会同时加载 python_d.dll python.dll 这样就会造成程序运行初始化python Py_Initialize() )时崩溃这个问题不知道是什么原因产生的。

 

3、所以在编译boost python 时,不需要下载python 的源码自己编译,只需要下载python 的安装包,安装相应的python 版本。也可以自己下载python 的源码编译出python release 版,编译boostPython debug release 都只依赖这个releasepyhon lib

 

4python 安装后例如在 C:\python27python.exec:\python27 目录下, python27.lib C:\Python27\libs 目录下, python27.dll 在系统的system32 目录下。

 

5boost 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 的命令提示符工具,如图:

vs2010 x64 下 boost Python 编译 - zhongzhe - 我的博客

 

执行命令 :   cd /D D:\boost_1_47_0\tools\build\v2\

将命令提示符窗口定位到 D:\boost_1_47_0\tools\build\v2 目录下,

vs2010 x64 下 boost Python 编译 - zhongzhe - 我的博客

 

执行命令: bootstrap.bat 开始 bjam 的编译,

vs2010 x64 下 boost Python 编译 - zhongzhe - 我的博客

  

编译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 的初始化函数。

拷贝后如下图:

vs2010 x64 下 boost Python 编译 - zhongzhe - 我的博客

 

依赖python的程序必须要有 pythonlib

 

参考了网上的一篇文章

http://china.ygw.blog.163.com/blog/static/68719746201152485054104/

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多