Ubuntu boost. python, boost. python
Install boost (only libboost-python-dev is not installed)
Sudo apt-get install libboost-all-dev
Create hello_ext.cpp and enter the following code:
1 char const * greet () {2 return "hello world"; 3} 4 5 # include <boost/python. hpp> 6 7 BOOST_PYTHON_MODULE (hello_ext) {8 using namespace boost: python; 9 def ("greet", greet); 10}
Storage, use the following command line to compile:
G ++-I/usr/include/python2.7-c-fPIC hello_ext.cpp-o hello_ext.og ++-shared-o hello_ext.so hello_ext.o-lpython2.7-lboost_python
In the directory where hello_ext is located, open the python shell
>>> Import hello_ext
>>> Print hello_ext.greet ()
Note:
-To add-lpython2.7 and-lboost_python, otherwise there will be a problem with a very complicated function not found, see http://stackoverflow.com/questions/1771063/no-such-file-or-directory-error-with-boost-python