Ubuntu boost. python, boost. python

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.