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.
- void show()
Declare the show Function
- {
- cout << "Boost.Python";
- }
- BOOST_PYTHON_MODULE(example)
Use BOOST_PYTHON_MODULE to name the module "example"
- {
- 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.