增强.pythongcc 5.2.0的字符串兼容性

2024-10-02 14:16:08 发布

您现在位置:Python中文网/ 问答频道 /正文

接受std::string输入的函数无法通过增强.pythongcc/5.2.0;gcc 4.8.3适用。

p、 我正在使用一个预先构建的libboost_Python.so.1.63. 你知道吗

C++代码

#include <boost/python.hpp>
#include <iostream>
using namespace boost::python;

void func(const std::string & hi)
{
    std::cout<<hi<<std::endl;
}

BOOST_PYTHON_MODULE(example)
{
  def("func", &func);
}

Python执行

>>> from example import *
>>> func("hi")
Boost.Python.ArgumentError: Python argument types in
    example.func(str)
did not match C++ signature:
    func(std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >)

Tags: 函数代码stringincludeexamplehigccfunc

热门问题