VS2017与pybind11一起使用时引发链接器错误

时间:2019-03-05 20:04:41

标签: pybind11

我正在使用VS2017在python内部使用C ++函数,并且正在使用python 3.7.2。在编译期间出现链接器错误。我的目标扩展名是.pyd。 我的源代码如下

class Pet {
public:
    Pet(const std::string &name) : name(name) { }
    void setName(const std::string &name_) { name = name_; }
    const std::string &getName() const { return name; }

    std::string name;
};


namespace py = pybind11;

PYBIND11_MODULE(pyBindLibrary, m) {
    py::class_<Pet>(m, "Pet")
        .def(py::init<const std::string &>())
        .def("setName", &Pet::setName)
        .def("getName", &Pet::getName);


Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol __imp_PyThread_tss_create    cpybind C:\Users\pkumar\source\repos\ConsoleApplicationCPP\cpybind\Source.obj   1   
Error   LNK2001 unresolved external symbol __imp_PyUnicode_AsEncodedString  cpybind C:\Users\pkumar\source\repos\ConsoleApplicationCPP\cpybind\Source.obj   1   
Error   LNK2001 unresolved external symbol __imp_PyBaseObject_Type  cpybind C:\Users\pkumar\source\repos\ConsoleApplicationCPP\cpybind\Source.obj   1   
Error   LNK2001 unresolved external symbol __imp_PyMem_Calloc   cpybind C:\Users\pkumar\source\repos\ConsoleApplicationCPP\cpybind\Source.obj   1   
....

0 个答案:

没有答案