boost python numpy_boost.python 与 boost.numpy安装的一些注意事项

在安装boost.numpy时遇到编译错误'builtin_float_dtype<128>未定义',原因是numpy中NPY_BITSOF_LONGDOUBLE与NPY_BITSOF_DOUBLE长度相等。解决方法是注释掉相关代码。编译boost.numpy需设置LIBRARY_TYPE为SHARED且大写。详细步骤包括创建boost-build.jam、Jamroot文件,配置路径并使用bjam进行编译,最后确保依赖库的正确放置。
摘要由CSDN通过智能技术生成

安装boost.numpy时编译出错

出错为builtin_float_dtype<128>未定义,该函数出现在boost.numpy/libs/src/dtype.cpp中:

#if NPY_BITSOF_LONGDOUBLE > NPY_BITSOF_DOUBLE

template <> struct builtin_float_dtype< NPY_BITSOF_LONGDOUBLE > {

static dtype get() { return DTYPE_FROM_CODE(NPY_LONGDOUBLE); }

};

template dtype get_float_dtype< NPY_BITSOF_LONGDOUBLE >();

template <> struct builtin_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE > {

static dtype get() { return DTYPE_FROM_CODE(NPY_CLONGDOUBLE); }

};

template dtype get_complex_dtype< 2 * NPY_BITSOF_LONGDOUBLE >();

#endif

由于numpy将NPY_BITSOF_LONGDOUBLE 和NPY_BITSOF_DOUBLE定义为相同长度,所以没有创建该函数,但在test/dtype_mod.cpp中出现了:

// floats and complex

p::def("accept_float32", accept);

p::def("accept_complex64", accept< std::complex >);

p::def("accept_float64", accept);

p::def("accept_complex128", accept< std::complex >);

if (sizeof(long double) > sizeof(double)) {

p::def("accept_longdouble", accept);

p::def("accept_clongdouble", accept< std::complex >);

}

可将它注销掉:

// floats and complex

p::def("accept_float32", accept);

p::def("accept_complex64", accept< std::complex >);

p::def("accept_float64", accept);

p::def("accept_complex128", accept< std::complex >);

/*if (sizeof(long double) > sizeof(double)) {

p::def("accept_longdouble", accept);

p::def("accept_clongdouble", accept< std::complex >);

}*/

利用cmake编译boost.numpy时将LIBRARY_TYPE设置为SHARED,注意必须为大写

如何利用boot.python和boost.numpy编译文件?

(1) 创建boost-build.jam

内容:

boost-build "d:/boost_1_59_0/tools/build/src" ;

上面路径对应boost的tools库

(2) 创建Jamroot文件

内容:

# Copyright David Abrahams 2006. Distributed under the Boost

# Software License, Version 1.0. (See accompanying

# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

import python ;

if ! [ python.configured ]

{

ECHO "notice: no Python configured in user-config.jam" ;

ECHO "notice: will use default configuration" ;

using python ;

}

# Specify the path to the Boost project. If you move this project,

# adjust this path to refer to the Boost root directory.

use-project boost

: D:/boost_1_59_0/ ;

lib boost_numpy : : boost_numpy . ;

# Set up the project-wide requirements that everything uses the

# boost_python library from the project whose global ID is

# /boost/python.

project

: requirements /boost/python//boost_python

boost_numpy

/boost//headers

: usage-requirements /boost//headers

;

# Declare the three extension modules. You can specify multiple

# source files after the colon separated by spaces.

python-extension wakeModel : main.cpp wakeModel.cpp ;

# Put the extension and Boost.Python DLL in the current directory, so

# that running script by hand works.

install convenient_copy

: wakeModel

: on SHARED_LIB PYTHON_EXTENSION

.

;

# A little "rule" (function) to clean up the syntax of declaring tests

# of these extension modules.

local rule run-test ( test-name : sources + )

{

import testing ;

testing.make-test run-pyd : $(sources) : : $(test-name) ;

}

# Declare test targets

#run-test wakeModel : wakeModel_ext wakeModel.py ;

(3) 运行命令:

bjam toolset=gcc release threading=multi

(4) 将libboost_python-mgw51-mt-1_59.dll和libboost_numpy.dll拷贝到当前目录,注意libboost_numpy.dll的依赖库要与libboost_python-mgw51-mt1_59.dll同名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值