-
Notifications
You must be signed in to change notification settings - Fork 13
/
README.md
120 lines (91 loc) · 5.1 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Boost Python Examples
- - -
* [C++ Boost](#C++-Boost)
- - -
### C++ Boost Python
* [Installation](#Boost-Installation-with-python3-support)
* [Ubuntu](#OS-Ubuntu-16.10)
* [Mac](#OS-Mac)
* [Demo](#Demo)
* [python3 hello_ext example](#python3-hello_ext)
* [python2 hello_ext example](#python2-hello_ext)
* Examples
* [hello_ext](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/hello_ext)
* [class_hello](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/class_hello)
* [class_member](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/class_member)
* [class_property](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/class_property)
* [inheritance](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/inheritance)
* [class_virtual](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/class_virtual)
* [class_virtual_nopure](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/class_virtual_nopure)
* [operators](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/operators)
* [special_operators](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/special_operators)
* [call_policies](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/call_policies)
* [overloading](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/overloading)
* Object Interface
* [basic_interface](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/basic_interface)
* [derived_object_types](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/derived_object_types)
* [extracting_c++_objects](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/extracting_c++_objects)
* [enums](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/enums)
* [reference_count](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/reference_count)
* [embedding](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/embedding)
* [iterators](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/iterators)
* [exception_translation](https://github.com/zpoint/Boost-Python-Examples/tree/master/Examples/exception_translation)
##### Boost Installation with python3 support
* OS Ubuntu 16.10
* From source
* Download the latest version [here](http://www.boost.org/)
* Description of **user-config.jam** please refer to [here](http://www.boost.org/build/doc/html/bbv2/overview/configuration.html)
tar -xzvf boost_1_65_1.tar.gz
cd boost_1_65_1
# sudo find / -name "python3.5m" # If you don't know where python3.5m is
# which python3 # If you don't know your python3 install directory
echo "using mpi ;
using gcc : : g++ ;
using python : 3.5 : /usr/bin/python3 : /usr/include/python3.5m : /usr/local/lib ;" > ~/user-config.jam
./bootstrap.sh --with-python=/usr/bin/python3 --with-python-version=3.5 --with-python-root=/usr/local/lib/python3.5 --prefix=/usr/local
sudo ./b2 install -a --with=all
sudo ldconfig
* From apt
sudo apt-get install libboost-all-dev
# link libboost_python3.so
sudo find / -name "libboost_python-py35.so"
# cd to where you find it
cd /usr/lib/x86_64-linux-gnu/
sudo ln -s libboost_python-py35.so libboost_python3.so
* OS Mac
brew install boost-python --with-python3
# if your python version or lib path is different from mine, please change
# INCLUDE_PATH and LIBPYTHON_PATH in makefile
# INCLUDE_PATH:
# shold be the path contains "pyconfig.h", below two command can help you find the path
# sudo find / -name "pyconfig.h"
# python3 -c "import sys; print('\n'.join(sys.path))"
# LIBPYTHON_PATH:
# on mac, with version python3.6, lib name is: libpython3.6.dylib
# sudo find / -name "libpython3.6"
##### Demo
* If you install from source, and you change the prefix path when install, you need also change the **BOOST_INC** and **BOOST_LIB** in **makefile**
* My default python version is python3.5 on Ubuntu, python3.6 on Mac, if you want to use with python 2.7, change **"PYTHON_VERSION"** in makefile
###### python3 hello_ext
git clone https://github.com/zpoint/Boost-Python-Examples.git
cd Boost-Python-Examples/Examples/hello_ext
make
python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello_ext
>>> hello_ext.greet()
'hello, world'
###### python2 hello_ext
git clone https://github.com/zpoint/Boost-Python-Examples.git
cd Boost-Python-Examples/Examples/hello_ext
vim makefile # change the first line "PYTHON_VERSION = None" to "PYTHON_VERSION = 2.7"
make
python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello_ext
>>> hello_ext.greet()
'hello, world'