Last active
December 3, 2018 16:12
-
-
Save YannickJadoul/5f99abf44696088027a8a4a5dd224198 to your computer and use it in GitHub Desktop.
Shared data between two pybind11 modules
This file contains hidden or 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 <pybind11/pybind11.h> | |
| #include "SharedCounter.h" | |
| PYBIND11_MODULE(bar, m) { | |
| m.def("inc", []() { return SharedCounter::getInstance().inc(); }); | |
| } |
This file contains hidden or 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
| cmake_minimum_required(VERSION 3.8) | |
| project(SharedDataPybind11) | |
| add_subdirectory(pybind11) | |
| add_library(SharedCounter SHARED SharedCounter.cpp) | |
| target_compile_features(SharedCounter PUBLIC cxx_std_11) | |
| if (WIN32) | |
| target_compile_definitions(SharedCounter PRIVATE SharedCounter_EXPORTS) | |
| endif() | |
| pybind11_add_module(foo foo.cpp) | |
| target_link_libraries(foo PRIVATE SharedCounter) | |
| pybind11_add_module(bar bar.cpp) | |
| target_link_libraries(bar PRIVATE SharedCounter) |
This file contains hidden or 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 <pybind11/pybind11.h> | |
| #include "SharedCounter.h" | |
| PYBIND11_MODULE(foo, m) { | |
| m.def("inc", []() { return SharedCounter::getInstance().inc(); }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment