我试图包装一些C ++函数以便在python中使用。例如,这是boost Python教程中的函数。
// Copyright Joel de Guzman 2002-2004. 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)
// Hello World Example from the tutorial
// [Joel de Guzman 10/9/2002]
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
当我将其编译成.pyc文件并尝试将其导入python时,我收到错误:
ImportError:C:\ hello_ext.pyc
中的错误幻数
我已经使用另一个论坛的方法检查了幻数,这似乎是错误的。我google了,我无法找到有关此错误消息的任何有用信息。我怀疑这在我的visual studio项目文件中是一个糟糕的设置,或者可能是我编译boost的方式?
我正在使用visual studio 2010 service pack 1,python 2.7.3和boost 1.53
我使用以下选项编译了boost。
b2 install toolset=msvc-10.0 variant=debug,release threading=multi link=shared runtime-link=shared --prefix="C:\boost"
答案 0 :(得分:1)
当你编译boost python时,你应该有一个共享库(例如我机器上的* .so),而不是.pyc文件..
这是一个关于如何构建boost python扩展的页面: http://wiki.python.org/moin/boost.python/BuildingExtensions