Last active
February 29, 2020 05:25
-
-
Save IlyaSkriblovsky/c548fe32538d7fc691fb49f9ce212776 to your computer and use it in GitHub Desktop.
Calling C++ dll from Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
extern "C" std::list<int>* create_list(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import adapt | |
print(adapt.create_list()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment