Saya memiliki kelas Foo() dan kelas Foo() memiliki fungsi dengan deklarasi berikut:
bool Foo::copyFile(const std::filesystem::path& src, const std::filesystem::path& dest)
Persyaratannya adalah kelas Foo harus memiliki binding Python. Saya menggunakan pybind11 untuk membuat binding Python.
Saya telah menulis yang berikut ini untuk membuat binding Python:
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "Foo.h"
namespace py = pybind11;
PYBIND11_MODULE(TestModule, m) {
py::class_ <Foo>(m, "Foo")
.def(py::init())
.def("copyFile",&Foo::copyFile);
};
Ini mengkompilasi OK dan saya dapat membuat file pyd binding Python. Ketika saya menggunakan binding Python untuk kelas Foo menggunakan:
from TestModule import Foo
f = Foo()
ret = f.copyFile("C:\Users\csaikia\Downloads\testfile_src", "C:\Users\csaikia\Downloads\testfile_dest")
itu memberikan TypeError. Saya menduga ini ada hubungannya dengan dukungan pybind11 untuk std::filesystem di c++17 karena saya tidak melihat ini terjadi dengan fungsi lain dari kelas yang memiliki std::string
atau std::vector
.
Kesalahan yang saya dapatkan adalah:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: copyFile(): incompatible function arguments. The following argument types are supported:
1. (self: TestModule.Foo, arg0: std::filesystem::path, arg1: std::filesystem::path) -> bool
Invoked with: <TestModule.Foo object at 0x0000000002A33ED8>, 'C:\\Users\\csaikia\\Downloads\\testfile_src', 'C:\\Users\\csaikia\\Downloads\\testfile_dest'
Did you forget to `#include <pybind11/stl.h>`? Or <pybind11/complex.h>,
<pybind11/functional.h>, <pybind11/chrono.h>, etc. Some automatic
conversions are optional and require extra headers to be included
when compiling your pybind11 module.
Saya baru mengenal pybind11. Dapatkah seseorang tolong bantu bagaimana saya bisa mengatasi ini?