網頁

2018年11月3日 星期六

pybind11 for Mac

1. 三種方式安裝pybind11
$ brew install pybind11
$ pip3 install pybind11
$ conda install -c conda-forge pybind11

2. 寫example.cpp




參考
https://pybind11.readthedocs.io/en/stable/basics.html#header-and-namespace-conventions

3. 執行Mac的編譯指令產生example.cpython-36m-darwin.so
$ g++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`

-undefined dynamic_lookup: Python gets linked dynamically without having all symbols resolved at link timepython3 -m pybind11 --includes: import pybind11 module
python3-config: output build options for python C/C++ extension
--extension-suffix: print the extension suffix used for binary extensions (產生example.cpython-36m-darwin.so)

參考
https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually
https://osmocom.org/issues/1678
https://blog.csdn.net/IAlexanderI/article/details/81003225
https://helpmanual.io/man1/python3-config/

4. 利用python call c++ function

















$ python3 example.py


沒有留言:

張貼留言