0

The function, which takes std::string input cannot be correctly exposed via boost.python with gcc/5.2.0; while gcc 4.8.3 works fine.

p.s. I am using a pre-built libboost_python.so.1.63.

C++ code

#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 execution

>>> 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> >)
Alex Pai
  • 115
  • 7
  • I think this is the proper duplicate: https://stackoverflow.com/questions/45417707/glibcxx-use-cxx11-abi-gcc-4-8-and-abi-compatibility – Matthieu Brucher Dec 21 '18 at 19:59
  • Thanks. Both `-D_GLIBCXX_USE_CXX11_ABI=0` and `#define _GLIBCXX_USE_CXX11_ABI 0` works. Is there a side effect to do that? – Alex Pai Dec 21 '18 at 20:17
  • Yes, means that you are using the old ABI version of libstdc++. But that's what distributions like RH6 are using, so you need the flag to get compatibility. – Matthieu Brucher Dec 21 '18 at 20:19
  • Possible duplicate of [\_GLIBCXX\_USE\_CXX11\_ABI, GCC 4.8 and ABI compatibility](https://stackoverflow.com/questions/45417707/glibcxx-use-cxx11-abi-gcc-4-8-and-abi-compatibility) – TylerH Dec 24 '18 at 02:24

0 Answers0