简体   繁体   中英

Attempting to Interface Python 3 with C++ using Boost

I've been trying to extend Python with C++ using Boost in Windows 7. This is the code I have so far:

C++ code, 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 code, 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"])
                    ]
      )

I try to build this by opening the command prompt and running "python setup.py build" in my Python32 directory. I've included the path to vcvarsall.bat in my environment variables.

The error I'm getting now:

error_image .

I have little experience with C++ and I'm new to Boost. Any help would be appreciated.

EDIT: This is being done in MVSC++ 2010, however I'm using the v9.0 toolset and have also tried in MVSC++ 2008 Express. The path to hellomodule.cpp is "C:\\Users\\Amir\\Documents\\Visual Studio 2010\\Projects\\BoostExample\\BoostExample\\hellomodule.cpp"

The compiler can't find hellomodule.cpp because it (probably) isn't in c:\\python32. Try moving hellomodule.cpp into c:\\python32 -- or, better yet, changing your directory to the path of hellomodule.cpp -- and rebuilding. It may lead to some other compiler errors, but at least you'll get past this first problem.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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