Wrapping c++ functions in python with ctypes on windows : function not found

怎甘沉沦 提交于 2019-12-06 05:54:41

The error reported by your Python is very clear.

function 'plop' not found

This means that the DLL does not export a function of that name. So, you need to export the function. Either with a .def file, or using __declspec(dllexport):

extern "C"
{
    __declspec(dllexport) int plop();
}

To inspect your DLL to debug issues like this, use dumpbin or Dependency Walker.

Note that since you do not specify calling convention, the default of __cdecl is used. That means that cdll is correct on the ctypes side.

You need to give your function "C" linkage to avoid name mangling. Declare it like this:

extern "C"
{
    int plop();
}

and it will then properly be called "plop" rather than being name-mangled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!