boost python异常处理_C++ boost.python折腾笔记

为了让当年研究生时写的图像处理系统重出江湖起到更大的作用,应研究生导师的意见,对原有的c++框架做了python扩展处理,为了避免遗忘,备注如下:

一、boost 编译

下载boost源码,这里使用boost 1.67,解压到目录,进行编译

安装Anaconda3-5.1.0-Windows-x86_64 默认路径安装

解压boost文件,在其目录中执行.\bootstrap.bat,会生成编译器b2.exe和bjam.exe

修改project-config.jam文件,加入python的版本及路径(不加入则会默认python2):

import option ;

using msvc ;

option.set keep-going : false ;

using python

: 3.6 # Version

: C:\\ProgramData\\Anaconda3\\python.exe # Python Path

: C:\\ProgramData\\Anaconda3\\include # include path

: C:\\ProgramData\\Anaconda3\\libs # lib path(s)

;

执行命令(我这里是vs 2010 故为msvc-10.0)`.\bjam.exe toolset=msvc-10.0 --with-python threading=multi link=shared address-model=64,在 stage\lib 目录中会生成 boost_numpy3-* 和 boost_python3-* 字样的文件

编译过程遇到了以下问题

(1)缺少头文件 无法打开包括文件:“inttypes.h

#include

编译时,找不到此文件,所以无法打开

方法:

1. 获取此文件

2. 放置此文件到目录:

VS2008,C:\Program Files\Microsoft Visual Studio 9.0\VC\include

VS2010,C:\Program Files\Microsoft Visual Studio 10.0\VC\include

(2)boost 1.67的bug   找不到库

C:\Boost\include\boost-1_67\boost\python\numpy\config.hpp

修改这一段

// enable automatic library variant selection ------------------------------//

#if !defined(BOOST_NUMPY_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_NUMPY_NO_LIB)

//

// Set the name of our library, this will get undef'ed by auto_link.hpp

// once it's done with it:

//

//#define BOOST_LIB_NAME boost_numpy##PY_MAJOR_VERSION##PY_MINOR_VERSION

#define _BOOST_PYTHON_CONCAT(N, M, m) N ## M ## m

#define BOOST_PYTHON_CONCAT(N, M, m) _BOOST_PYTHON_CONCAT(N, M, m)

#define BOOST_LIB_NAME BOOST_PYTHON_CONCAT(boost_numpy, PY_MAJOR_VERSION, PY_MINOR_VERSION)

//

// If we're importing code from a dll, then tell auto_link.hpp about it:

//

#ifdef BOOST_NUMPY_DYNAMIC_LIB

# define BOOST_DYN_LINK

#endif

//

// And include the header that does the work:

//

#include

#endif // auto-linking dis

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值