Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the related programs used when compiling with Boost.Python

Shulou Source: shulou.com Published: 2022-06-02 23:25:55 10月02日 Update

In this issue, the editor will bring you about the relevant programming used when compiling with Boost.Python. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Boost is a portable C++ standard library, which is equivalent to the continuation and expansion of STL. The Boost library also provides support for C++ to write Python extensions. If you use C++ to write extensions for Python, using Boost.Python will make the program easier.

Compile Boost.Python

You need to compile Boost.Python before you can program with it. Because the Boost library is too large, you can compile only Boost.Python if there is no other need. Take VC++ 6. 0 as an example, the compilation steps are as follows.

(1) download the Boost library source file from the Boost official website and extract it to a directory.

Required for Python embedding in C _ Candle + (lower level embedding)

Embed Python into the concrete operation of Candlestick + tuple operation for application

The actual operation of embedding Python into Candlestick + module and function

The operation steps of embedding Python into Candlestick + module and function

Concrete Analysis of Python embedded in C instance

(2) add the directory unzipped to Boost 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 the [Build] | [Batch Build] command to compile Debug and Release versions of Boost.Python, respectively.

(5) after compilation, dynamic link libraries and library files will be generated in the "libs\ python\ build\ bin-stage" subdirectory in the Boost directory. Because Python extensions written in Boost.Python require "boost_python.dll" and "boost_python_debug.dll" files at run time depending on the version. For convenience, you can put it in the "system32" directory under the Windows installation directory. Otherwise, you need to put it in the same directory as the Python extension.

(6) add the "libs\ python\ build\ bin-stage" subdirectory under the Boost directory to [Library files] in VC++ 6.0.After completing the above settings, you can use Boost.Python to write Python extensions.

Extend and embed Python with Boost.Python

C++ classes and functions can be used within Python through Boost.Python. Like SWIG, Boost.Python simplifies the code for writing Python extensions without using Python/C API. But unlike SWIG, Boost.Python is a class library that eliminates the need for interface files.

Initialization and method list

You can name the module name in Boost.Python by using BOOST_PYTHON_MODULE. In BOOST_PYTHON_MODULE, you can use def to implement a list of methods defined using Python/C API. Here is a simple example.

Void show ()

Declare the show function

{cout

Tags: Compiling directories functions modules programming subdirectories files methods different content steps analysis no professional small and medium code examples rich in content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple OPPO Reno Redmi NVidia