Skip to content

Commit d30f241

Browse files
author
zpoint
committed
boost examples
1 parent f51134b commit d30f241

32 files changed

Lines changed: 715 additions & 12 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__
2+
*.o
3+
*.so
4+
*.pyd

Examples/class_hello/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# class_hello
2+
3+
###### python3 class_hello
4+
5+
make
6+
python3
7+
8+
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
9+
[GCC 5.4.0 20160609] on linux
10+
Type "help", "copyright", "credits" or "license" for more information.
11+
>>> import class_hello
12+
>>> world = class_hello.World()
13+
default constructor
14+
>>> world.greet()
15+
''
16+
>>> world = class_hello.World("I am world")
17+
constructor of struct World
18+
>>> world.greet()
19+
'I am world'
20+
>>> world.set("Good")
21+
>>> world.greet()
22+
'Good'
23+
>>> quit()
24+

Examples/class_hello/makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PYTHON_VERSION = 3.5
2+
TARGET = class_hello
3+
4+
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
5+
6+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7+
8+
# location of the Boost Python include files and library
9+
10+
# install step
11+
# tar -xzvf boost_1_65_0.tar.gz
12+
# ./bootstrap.sh --with-python=/usr/bin/python3 --with-python-version=3.5 --with-python-root=/usr/local/lib/python3.5 --prefix=/usr/local
13+
# sudo ./b2 install -a --with=all
14+
# sudo ldconfig
15+
16+
BOOST_INC = /usr/local/include/boost
17+
BOOST_LIB = /usr/local/lib
18+
19+
20+
ifeq ($(PYTHON_VERSION), 3.5)
21+
BOOST = lboost_python3
22+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
23+
else
24+
BOOST = lboost_python
25+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
26+
endif
27+
28+
29+
$(TARGET).so: $(TARGET).o
30+
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
31+
32+
$(TARGET).o: $(TARGET).cpp
33+
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

Examples/class_member/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# class_member
2+
3+
###### python3 class_member
4+
5+
make
6+
python3
7+
8+
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
9+
[GCC 5.4.0 20160609] on linux
10+
Type "help", "copyright", "credits" or "license" for more information.
11+
>>> import class_member
12+
>>> var = class_member.Var("I am Var")
13+
>>> var.name
14+
'I am Var'
15+
>>> var.value
16+
0.0
17+
>>> var.value = 3
18+
>>> var.value
19+
3.0
20+
>>> var.name = "!"
21+
Traceback (most recent call last):
22+
File "<stdin>", line 1, in <module>
23+
AttributeError: can't set attribute
24+
25+
26+

Examples/class_member/makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PYTHON_VERSION = 3.5
2+
TARGET = class_member
3+
4+
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
5+
6+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7+
8+
# location of the Boost Python include files and library
9+
10+
# install step
11+
# tar -xzvf boost_1_65_0.tar.gz
12+
# ./bootstrap.sh --with-python=/usr/bin/python3 --with-python-version=3.5 --with-python-root=/usr/local/lib/python3.5 --prefix=/usr/local
13+
# sudo ./b2 install -a --with=all
14+
# sudo ldconfig
15+
16+
BOOST_INC = /usr/local/include/boost
17+
BOOST_LIB = /usr/local/lib
18+
19+
20+
ifeq ($(PYTHON_VERSION), 3.5)
21+
BOOST = lboost_python3
22+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
23+
else
24+
BOOST = lboost_python
25+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
26+
endif
27+
28+
29+
$(TARGET).so: $(TARGET).o
30+
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
31+
32+
$(TARGET).o: $(TARGET).cpp
33+
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

Examples/class_property/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# class_property
2+
3+
###### python3 class_property
4+
5+
make
6+
python3
7+
8+
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
9+
[GCC 5.4.0 20160609] on linux
10+
Type "help", "copyright", "credits" or "license" for more information.
11+
>>> import class_property
12+
>>> num = class_property.Num()
13+
>>> num.rovalue
14+
10.0
15+
>>> num.value
16+
10.0
17+
>>> num.value = 3
18+
>>> num.value
19+
3.0
20+
>>> num.rovalue = 3
21+
Traceback (most recent call last):
22+
File "<stdin>", line 1, in <module>
23+
AttributeError: can't set attribute
File renamed without changes.

Examples/class_property/makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PYTHON_VERSION = 3.5
2+
TARGET = class_property
3+
4+
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
5+
6+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7+
8+
# location of the Boost Python include files and library
9+
10+
# install step
11+
# tar -xzvf boost_1_65_0.tar.gz
12+
# ./bootstrap.sh --with-python=/usr/bin/python3 --with-python-version=3.5 --with-python-root=/usr/local/lib/python3.5 --prefix=/usr/local
13+
# sudo ./b2 install -a --with=all
14+
# sudo ldconfig
15+
16+
BOOST_INC = /usr/local/include/boost
17+
BOOST_LIB = /usr/local/lib
18+
19+
20+
ifeq ($(PYTHON_VERSION), 3.5)
21+
BOOST = lboost_python3
22+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
23+
else
24+
BOOST = lboost_python
25+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
26+
endif
27+
28+
29+
$(TARGET).so: $(TARGET).o
30+
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
31+
32+
$(TARGET).o: $(TARGET).cpp
33+
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

0 commit comments

Comments
 (0)