Related programming used for compiling with Boost. Python

Source: Internet
Author: User

The following article focuses on the Boost of the hybrid system interface. A detailed introduction to the practical application of Python in extension and embedding Python, and how to use Boost in practical applications. python introduces the actual operation steps of using C ++ classes and functions in Python.

Boost is a portable C ++ standard library, which is equivalent to the continuation and expansion of STL. The Boost Library also provides support for compiling Python extensions in C ++. If C ++ is used to write extensions for Python, using Boost. Python will simplify the program.

Compile Boost. Python

You must compile Boost. Python to program it. Because the Boost library is too large, you can compile Boost. Python only if there is no other need. Taking VC ++ 6.0 as an example, the compilation procedure is as follows.

1) download the Boost Library source file from the Boost official website and decompress it to a directory.

  • Python embedded in C/C ++ at a lower level)
  • Embed Python into the C/C ++ tuples for specific applications
  • How to embed Python into C/C ++ modules and functions
  • How to embed Python into C/C ++ modules and functions
  • Analysis of Python Embedded C instance

2) Add the directory to which Boost is extracted to Include files in VC ++ 6.0,

3) go to the "libs \ python \ build \ VisualStudio" subdirectory under the Boost directory and open the "boost_python.dsw" file in VC ++ 6.0.

4) Click Build> Batch Build to compile the Debug and Release versions of Boost. Python respectively.

5) After compilation, the dynamic link library and library file will be generated in the "libs \ python \ build \ bin-stage" subdirectory under the Boost directory. Because Python extensions compiled using Boost. Python need the "boost_python.dll" and "boost_python_debug.dll" files according to different versions during runtime. For convenience, you can put it in the "system32" directory under the Windows installation directory. Otherwise, you need to put the Python extension in the same directory.

6) add the "libs \ python \ build \ bin-stage" subdirectory under the Boost directory to Library files in VC ++ 6.0,

After completing the preceding settings, you can use Boost. Python to write Python extensions.

Use Boost. Python to expand and embed Python

With Boost. Python, you can use C ++ classes and functions in Python. Like SWIG, Boost. Python simplifies the compilation of Python extension code without using Python/C APIs. Unlike SWIG, Boost. Python is a class library that does not need to use interface files.

Initialization and method list

In Boost. Python, you can use BOOST_PYTHON_MODULE to name the module name. In BOOST_PYTHON_MODULE, def can be used to implement a list of methods defined using Python/C APIs. The following is a simple example.

 
 
  1. void show() 

Declare the show Function

 
 
  1. {  
  2. cout << "Boost.Python";  
  3. }  
  4. BOOST_PYTHON_MODULE(example)   

Use BOOST_PYTHON_MODULE to name the module "example"

 
 
  1. {  
  2. def("show",show);   

Equivalent to defining method list

The above is an introduction to how to compile Boost. Python and how to use Boost. Python to expand and embed 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.