Compile boost.python in mingw

zhaozj2021-02-11  193

Sometimes, I wrote that it is purely for fun. For example, for Python and Boost. Many friends around you, see what I am happy, I will ask me like an alien: "Is this use?"

I started to feel very depressed, and later learned to smile. Why do you want to fight? In order to live, it is not a wrong attitude, but hugging this attitude, it is impossible to tell them clearly, this kind of life is fun. If it is just to make a living, I should have peace of mind to use RAD for a lifetime. However, I like C , like Python. This language can make me have fun. Although I may never become Bjarne, but I can be a happy person, is this not very good?

As a pure C "enthusiast (not occupation C programmer), I rarely use VC. For a long time, I have been using the built-in GCC DEV C . Later, I also downloaded a MingW, integrated in DEV C , as a compiler kernel. I don't know how much "players" like me on 9CBS. However, from the post on the forum, all friends who use MingW Python Boost like me have encountered a headache: Boost.Python cannot be installed.

The specific manifestation of this problem is that when compiling Boost.Python with MingW, it will be prompted to not find some definitions, and finally the last one or more errors. The specific number seems to have different. My machine usually is 6, and there is a friend, and his machine is generally 9 mistakes. This problem has plagued our C rookie for a long time. Because the same problem does not appear on the VC. Finally, an accidental opportunity, I found, in fact, this problem is not mysterious: in the compilation process of Boost.pyhton, you need to call a static library pythonxx.lib (XX is two digits, depending on the version of Python, I am python22.lib). Python's Windows version is compiled using VC! So in the VC, there will be no such problem. MINGW usually does not recognize this VC-compiled static library. The same problem is not only compiled Boost.Python. This problem will occur as long as you use the installation version of Python with MingW.

How to do? Compile the Python source code with mingw? This sounds a good idea, fundamentally solve the problem. But I am very disappointed that in me, use Cygwin to compile the python source code correctly, and Mingw is not. Probably because of my method. If you know, please advise. From another perspective, just get a LIB file compiled by a MingW. And this method is actually mentioned in Python's documentation - although not to say to Boost.Python, this is indeed the easiest way. Let me sort it out and introduce it.

1. We need a tool to generate the DETHON22.LIB DEF file. This DEF is actually obtained from python22.dll (dynamic link library is language and compiler). First download PEXPORTS 0.42H (http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip). After decompression, you can find an executable PEXPORTS.EXE in the bin directory. For convenience, we can add this directory to the path; 2. Find python22.dll in the system directory, copy it into a separate directory (I put it in my python / dlls, is one And processes other DLLs);

3. In the command line mode, go to the directory where Python22.dll is placed, execute: pexports python22.dll> python22.def;

4, now, in this directory, we can find python22.def, open it with the text editor, will see those definitions that can not be found when compiling boost.python, is there;

5. Use GCC's attachment tool to generate a static file, now execute: dlltool --dllname python22.dll --def python22.def --output-lib python22.lib.

We can now find the dream of python22.lib.

With the same method, I generated other several lib files of the MINGW version, such as Zlib.Lib, Parser.Lib, etc. Now, put them in a new directory (you can also specify a directory directly when generating them). Set the libs directory variable required by Boost.Python to this directory, you can compile Boost.Python correctly!

Welcome all friends who use mingw to come to Boost.Python world! At this time, you have probably you have been experimenting with the example of Boost, and even you start to extend Python with Boost.

转载请注明原文地址:https://www.9cbs.com/read-4589.html

New Post(0)