Install boost (no attempt to install Libboost-python-dev only)
sudo Install Libboost-all-dev
New Hello_ext.cpp, enter the following code
1CharConst *Greet () {2return hello world< Span style= "color: #800000;" > "; } 4 5 #include <boost/python.hpp> 7 boost_python_module (hello_ext) {using namespace boost::p ython; "greet" 10}
Storage, use the following command-line compilation:
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 the Hello_ext is located, open the Python shell
>>> Import Hello_ext
>>> Print Hello_ext.greet ()
Precautions:
-To add-lpython2.7 and-lboost_python, otherwise a very complex function could not find the problem, see http://stackoverflow.com/questions/1771063/ No-such-file-or-directory-error-with-boost-python
Ubuntu Boost.python