Skip to content

Instantly share code, notes, and snippets.

@IlyaSkriblovsky
Last active February 29, 2020 05:25
Show Gist options
  • Save IlyaSkriblovsky/c548fe32538d7fc691fb49f9ce212776 to your computer and use it in GitHub Desktop.
Save IlyaSkriblovsky/c548fe32538d7fc691fb49f9ce212776 to your computer and use it in GitHub Desktop.
Calling C++ dll from Python
from cython.operator cimport dereference as deref
from libcpp.list cimport list as c_list
cdef extern from "test.h":
c_list[int]* c_create_list "create_list" ()
def create_list():
l = c_create_list()
try:
return deref(l)
finally:
del l
#include <list>
#include "test.h"
using namespace std;
list<int>* create_list() {
list<int> *l = new list<int>();
l->push_back(1);
l->push_back(2);
l->push_back(3);
return l;
}
#include <list>
extern "C" std::list<int>* create_list();
import adapt
print(adapt.create_list())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment