gpt4 book ai didi

c++ - 使用 boost 的 C++ 中的 hello world python 扩展?

转载 作者:IT王子 更新时间:2023-10-29 01:10:36 24 4
gpt4 key购买 nike

这是我第一次尝试使用 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

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: fatal error: pyconfig.h: No such file or directory compilation terminated.

这一行准确地说明了为什么它不起作用。您的编译器不知道 pyconfig.h 文件在哪里。您在这里有两个选择:

  1. 将 pyconfig.h 放在一个位置g++ 知道(即你的项目目录)
  2. 添加 -I DIRECTORY(这是大写字母 i,不是小写的 L) 标志到 g++ 那将使 g++ 在 DIRECTORY 中搜索头文件

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

关于c++ - 使用 boost 的 C++ 中的 hello world python 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6007185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com