hello world python扩展在c ++使用boost? [英] hello world python extension in c++ using boost?

查看:359
本文介绍了hello world python扩展在c ++使用boost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我简单的第一次尝试使用boost的python扩展。有人可以帮助我理解导致编译错误的原因吗?

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

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:没有此类文件或目录编译终止。
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.


推荐答案


/ usr /include/boost/python/detail/wrap_python.hpp:50:23:
致命错误:pyconfig.h:没有这样的文件
或目录编译终止。

/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory compilation terminated.

这一行说明了为什么它不工作。你的编译器不知道pyconfig.h文件在哪里。这里有两个选项:

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:


  1. 将pyconfig.h放在
    g ++知道的位置(即
    项目的目录)

  2. 添加-I DIRECTORY(这是资本i,
    不小写L)标记为g ++,
    将使g ++搜索头文件的DIRECTORY

  1. place pyconfig.h in a location that g++ knows about (i.e. your project's directory)
  2. add -I DIRECTORY (this is capital i, not lowercase L) flag to g++ that will make g++ search DIRECTORY for header files




g ++ -I / path / to / my / include / files main.cpp

g++ -I /path/to/my/include/files main.cpp

这篇关于hello world python扩展在c ++使用boost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆