Skip to content

Instantly share code, notes, and snippets.

@jrk
Created February 9, 2018 20:10
Show Gist options
  • Save jrk/acfc1630b2e5a6805b074fe305270c16 to your computer and use it in GitHub Desktop.
Save jrk/acfc1630b2e5a6805b074fe305270c16 to your computer and use it in GitHub Desktop.
Trivial PyBind11 test module
#include <pybind11/pybind11.h>
PYBIND11_MODULE(foobar, m) {
m.doc() = "pybind11 example plugin";
}
PYBIND11_INCLUDE ?= # -Ipath/to/pybind/include if not in other paths
PREFIX ?= $(shell python3-config --prefix)
INCLUDES = ${PYBIND11_INCLUDE} -I${PREFIX}/include/python3.6m -I${PREFIX}/include
CFLAGS = -std=c++11 ${INCLUDES}
LDFLAGS = -arch x86_64 -L${PREFIX}/lib -lpython3.6m -ldl
foobar.so: foobar.cpp
c++ ${CFLAGS} ${LDFLAGS} foobar.cpp -shared -o foobar.so
clean:
rm -f foobar.so
test: foobar.so
${PREFIX}/bin/python3.6m -c 'import foobar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment