H
H
HallEffect2014-04-11 12:30:49
Python
HallEffect, 2014-04-11 12:30:49

How to use ctypes, c++ and python?

Understanding the ctypes tool to call dll from python code. It is not possible to call functions from a dll compiled from C ++, although the same source code, but already in C, compiled into a dll, works fine, all functions are called.
C/C++ code:
int test(int x)
{
return x;
}
Python code:
from ctypes import *
c_testlib = cdll.LoadLibrary('libtest.dll')
c_test=c_testlib.test
Error:
AttributeError: function 'test' not found
Are Ctypes and C++ not friends? What are the options for calling functions from already written dlls in C++?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
C00Lman, 2014-04-11
@HallEffect

extern "C"it is necessary to write before the functions so that the compiler in the dll calls them according to C, and not according to C ++

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question