繁体   English   中英

尝试使用Boost将Python 3与C ++接口

[英]Attempting to Interface Python 3 with C++ using Boost

我一直在尝试在Windows 7中使用Boost使用C ++扩展Python。这是我到目前为止的代码:

C ++代码hellomodule.cpp:

#include <iostream>
using namespace std;

void say_hello(const char* name) {
    cout << "Hello " << name << "!\n";
}

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

BOOST_PYTHON_MODULE(hello) {
    def("say_hello", say_hello);
}

Python代码setup.py:

#!/usr/bin/env python

from distutils.core import setup
from distutils.extension import Extension

setup(name="PackageName",
      ext_modules = [
          Extension("hello", ["hellomodule.cpp"],
                    libraries = ["boost_python"])
                    ]
      )

我尝试通过打开命令提示符并在我的Python32目录中运行“ python setup.py build”来构建它。 我已经在我的环境变量中包括了vcvarsall.bat的路径。

我现在得到的错误:

error_image

我对C ++的经验很少,对Boost还是不熟悉。 任何帮助,将不胜感激。

编辑:这是在MVSC ++ 2010中完成的,但是我正在使用v9.0工具集,并且也在MVSC ++ 2008 Express中进行了尝试。 hellomodule.cpp的路径是“ C:\\ Users \\ Amir \\ Documents \\ Visual Studio 2010 \\ Projects \\ BoostExample \\ BoostExample \\ hellomodule.cpp”

编译器找不到hellomodule.cpp,因为它(可能)不在c:\\ python32中。 尝试将hellomodule.cpp移到c:\\ python32中-或者更好的是,将目录更改为hellomodule.cpp的路径-并重建。 它可能会导致其他一些编译器错误,但至少您会克服第一个问题。

祝好运。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM