2013-10-24 4 views
0

파이썬 스크립트에 C++ 수치 레시피를 사용하고 싶지만 부스트 파이썬 라이브러리에서 몇 가지 사항을 컴파일하는 데 문제가 있습니다. 구체적으로 amoeba 함수를 파이썬에 공개하려고합니다. 나는 BJam보다는 Make를 사용한다.부스트 :: 파이썬 컴파일 문제

[email protected]:~/Desktop/Boost Python Test$ make 
g++ -I/usr/include/python2.7 -I/usr/include -fPIC -c amoeba_py.C 
In file included from /usr/local/include/boost/python/object/make_instance.hpp:10:0, 
       from /usr/local/include/boost/python/object/make_ptr_instance.hpp:8, 
       from /usr/local/include/boost/python/to_python_indirect.hpp:11, 
       from /usr/local/include/boost/python/converter/arg_to_python.hpp:10, 
       from /usr/local/include/boost/python/call.hpp:15, 
       from /usr/local/include/boost/python/object_core.hpp:14, 
       from /usr/local/include/boost/python/args.hpp:25, 
       from /usr/local/include/boost/python.hpp:11, 
       from amoeba_py.C:73: 
/usr/local/include/boost/python/converter/registered.hpp: In function ‘const boost::python::converter::registration& 
boost::python::converter::detail::registry_lookup2(T& (*)()) [with T = double(const NRVec<double>&)]’: 
/usr/local/include/boost/python/converter/registered.hpp:94:40: instantiated from ‘const >boost::python::converter::registration& boost::python::converter::detail::registry_lookup1(boost::type<T>) [with T = double (&)(const NRVec<double>&)]’ 
/usr/local/include/boost/python/converter/registered.hpp:105:23: instantiated from const boost::python::converter::registration& boost::python::converter::detail::registered_base<double (&)(const NRVec<double>&)>::converters’ 
/usr/local/include/boost/python/converter/arg_from_python.hpp:269:99: instantiated from ‘boost::python::converter::pointer_arg_from_python<T>::pointer_arg_from_python(PyObject*) [with T = double (*)(const NRVec<double>&), PyObject = _object]’ 
/usr/local/include/boost/python/arg_from_python.hpp:70:18: instantiated from ‘boost::python::arg_from_python<T>::arg_from_python(PyObject*) [with T = double (*)(const NRVec<double>&), PyObject = _object]’ 
/usr/local/include/boost/preprocessor/iteration/detail/local.hpp:43:1: instantiated from >‘PyObject* boost::python::detail::caller_arity<5u>::impl<F, Policies, Sig>::operator((PyObject*, PyObject*) [with F = void (*)(NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&), Policies = boost::python::default_call_policies, Sig = boost::mpl::vector6<void, NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&>, PyObject = _object]’ 
/usr/local/include/boost/python/object/py_function.hpp:38:33: instantiated from ‘PyObject* boost::python::objects::caller_py_function_impl<Caller>::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller<void (*)(NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&), boost::python::default_call_policies, boost::mpl::vector6<void, NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&> >, PyObject = _object]’ amoeba_py.C:79:1: instantiated from here 
/usr/local/include/boost/python/converter/registered.hpp:86:7: error: no matching function >for call to ‘register_shared_ptr1(double (*)(const NRVec<double>&))’ 
/usr/local/include/boost/python/converter/registered.hpp:86:7: note: candidate is: 
/usr/local/include/boost/python/converter/registered.hpp:77:3: note: template<class T> void boost::python::converter::detail::register_shared_ptr1(const volatile T*) 
make: *** [amoeba_py.o] Error 1 

누군가가 나에게이 오류가 무엇을 의미하는지 해독에 도움 아마 나에게 내 프로젝트를 완료하는 데 도움이되는 몇 가지 팁을 줄 수 : 이것은 내가 컴파일 할 때 내가 무엇을 얻을 수 있습니다. 고전적인 Boost Python 예제가 잘 컴파일된다는 것은 주목할 가치가 있습니다. 감사합니다.

여기서 문제가되는 텍스트입니다 (행 73-79)

#include <boost/python.hpp> 
using namespace boost::python; 

BOOST_PYTHON_MODULE(amoeba) 
{ 
    def("amoeba", NR::amoeba); 
} 
+0

당신이 * amoeba_py.C *에서 코드의 잘못된 부분 (들)을 게시하시기 바랍니다 수 :

코드는 다음과 같이한다고? 오류 메시지에 언급 된 73 번과 79 번 줄을 봅니다. 그 줄에는 무엇이 있습니까? – Praetorian

+0

@Praetorian OK! 문제의 코드를 추가했습니다. ps에 감사 드리며 숫자로 구성된 조리법 기능이 필요한 경우 [link] http://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf) 여기에서 찾으실 수 있습니다. – user2917789

+0

아래 답변에 게시 된 링크가 문제를 설명하는 것처럼 보입니다. 당신의'amoeba' 함수는 함수 포인터를 취해 그것을 파이썬에 노출시키기 위해서 당신은 그것을위한 래퍼를 만들어야 할 것입니다. – Praetorian

답변

0

난 당신이 this question을 물어 사람에 비슷한 문제가 발생하는 의심. C++ 코드에서 함수 포인터를 인수로 전달하고 있습니까? 그렇다면 파이썬에서 그렇게 할 수 없습니다 - 이유에 대한 답을보십시오.

0

참조 연산자를 잊어 버렸습니다. 따라서 defconst volatile T* 대신 예상되는 매개 변수 유형이 double (*)(const NRVec<double>&)입니다.

BOOST_PYTHON_MODULE(amoeba) 
{ 
    def("amoeba", &NR::amoeba); 
}