File tree Expand file tree Collapse file tree 3 files changed +5
-13
lines changed
python-bindings/overview_article Expand file tree Collapse file tree 3 files changed +5
-13
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python
2- """ Simple examples of calling C functions through ctypes module. """
32import pybind11_example
43
54
65if __name__ == "__main__" :
76 # sample data for our call:
8- x = 6
9- y = 2.3
7+ x , y = 6 , 2.3
108
119 answer = pybind11_example .cpp_function (x , y )
1210 print (f" In Python: int: { x } float { y :.1f} return val { answer :.1f} " )
13-
Original file line number Diff line number Diff line change 11#include < pybind11/pybind11.h>
22#include < cppmult.hpp>
33
4-
54PYBIND11_MODULE (pybind11_example, m) {
65 m.doc () = " pybind11 example plugin" ; // optional module docstring
76 m.def (" cpp_function" , &cppmult, " A function which multiplies two numbers" );
87}
9-
Original file line number Diff line number Diff line change @@ -57,20 +57,17 @@ def test_cffi(c):
5757@invoke .task ()
5858def build_pybind11 (c ):
5959 """ Compile and link the shared library (DLL) for the sample C++ code."""
60- # compile and link the c++ library
61- invoke .run ("g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC " \
62- "-I /usr/include/python3.7 " \
63- "cppmult.cpp " \
64- "-o libcppmult.so "
60+ # compile and link the cmult c++ library
61+ invoke .run ("g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
62+ "cppmult.cpp -o libcppmult.so "
6563 )
6664 # compile and link the pybind11 wrapper library
6765 invoke .run ("g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
6866 "`python3 -m pybind11 --includes` "
6967 "-I /usr/include/python3.7 -I . "
7068 "pybind11_wrapper.cpp "
7169 "-o pybind11_example`python3.7-config --extension-suffix` "
72- "-L. -lcppmult "
73- "-Wl,-rpath,. "
70+ "-L. -lcppmult -Wl,-rpath,. "
7471 )
7572
7673@invoke .task ()
You can’t perform that action at this time.
0 commit comments