c++ 中的 hello world python 扩展使用升压?
这是我使用 boost 进行 python 扩展的第一次简单尝试。有人可以帮助我了解导致编译错误的原因吗?
#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);
}
user@host:~$g++ main.cpp -o test.so
在 /usr/include/boost/python/detail/prefix.hpp:13:0、/usr/include/boost/python/module.hpp:8、main.cpp:8 包含的文件中: /usr/include/boost/python/detail/wrap_python.hpp:50:23:致命错误:pyconfig.h:没有这样的文件或目录编译终止。
Here's my simple first attempt at a python extension using boost. Can someone help me to understand what's causing the compilation error?
#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);
}
user@host:~$g++ main.cpp -o test.so
In file included from /usr/include/boost/python/detail/prefix.hpp:13:0, from /usr/include/boost/python/module.hpp:8, from main.cpp:8:
/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory compilation terminated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这一行准确地说明了它不起作用的原因。您的编译器不知道 pyconfig.h 文件在哪里。这里有两个选择:
g++ 知道(即你的
项目目录)
不是小写 L) 标记为 g++
将使 g++ 在 DIRECTORY 中搜索头文件
This line tells exactly why it doesn't work. Your compiler doesn't know where is the pyconfig.h file. You have two options here:
g++ knows about (i.e. your
project's directory)
not lowercase L) flag to g++ that
will make g++ search DIRECTORY for header files
如果您在 NetBeans 中遇到此问题,只需在 NetBeans 附加包含选项中添加“/usr/include/python 2.7/”文件夹即可。您将在属性中获得此附加包含选项。
If you face this problem in your NetBeans then just add "/usr/include/python 2.7/" folder in your NetBeans additional include option. You will get this additional include option in properties.
您需要将 pyconfig.h 放在同一目录中
You need to place pyconfig.h in same directory