7
我用我的C++代码从Python中的Visual C++(由升压包裹),具有带来很大的麻烦不工作。升压Python的Hello World示例在Python
好了,所以我使用的工具有:Visual Studio 2010中,BoostPro 1_47,Windows 7和Python 2.7版(32位)。
我有下面的代码编译很好地在Visual Studio 2010:
#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>
using namespace boost::python;
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set);
}
它的格式为:Win32控制台应用程序>>>空项目/ DLL。
在“项目属性”:
VC++ DIRECTORIES:
I added:
>>> INCLUDE DIRECTORIES: C:\Program Files\boost\boost_1_47;C:\Python27\include .
>>> LIBRARY DIRECTORIES: C:\Program Files\boost\boost_1_47\lib;C:\Python27\libs
所有这一切都使得C++文件构建但我不能用Python访问它。
这是Python的说什么,当我尝试使用模块:
">>> import hello
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import hello
ImportError: No module named hello
所以我想我的问题是...我怎样才能让Python找到它???
当C++代码编译它创建一个DLL文件。我必须更改文件的位置吗?如果是这样,我应该把它放在哪里?
您的帮助将不胜感激
谢谢Constantinius! :D我终于得到这个工作,几小时,几小时后,试图让boost.python做它的事情。 – user1449530
你能提供一个你已经做了成功的秘诀吗? – Noam
我还必须将包含Boost Python * .lib和* .dll文件的目录添加到PATH –