Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 794 Bytes

README.md

File metadata and controls

42 lines (28 loc) · 794 Bytes

CMake emsripten/pybind11 cross-compilation example

This is an example for compiling a C++ library using CMake and either pybind11 or emscripten. It also provides an example of its usage on a html page and a python module.

Install emscripten

sudo apt-get install emscripten

Compile to javascript

emcmake cmake -B build/ -DTARGET_TYPE="javascript"
cmake --build build/

Install pybind11

pip3 install "pybind11[global]"

Compile to python

cmake -B build/ -DTARGET_TYPE="python"
cmake --build build/

Run javascript

Just start a web server on this directory and navigate to host:port/index.html.

Run python

Move the compiled library and run main.py.

mv build/binding.<ext> binding.<ext>
python3 main.py