Puzzling dependency of Boost.Python 1.54 (debug build) to Python27.lib on Windows

僤鯓⒐⒋嵵緔 提交于 2019-12-01 06:53:24
François Beaune

I fixed the problem, thanks to hints found in this post: Visual C++ debug library naming convention.

Basically, the header file pyconfig.h that ships with Python (in C:\Python27\include\) forces linking to python27_d.lib in Debug build (via a #pragma comment() directive), regardless of whether this library exists or not.

The trick is to never include Python.h directly, but instead to include Boost's wrapper for that file, boost/python/detail/wrap_python.hpp which takes care of disabling the offending #pragma comment() directive.

Including boost/python/detail/wrap_python.hppinstead of Python.h allows you to use a release version of Python even when building a debug version of your program.

In case you have compiled yourself a debug version of Python, you can build a debug version of Boost that links against your debug version of Python. (I am using VS2013, but the process should be the same with VS2010 and VS2012).

First create a text file called, eg, my_config.bjam conatining:

using python : 2.7                                     #version 
: C:\\Python-2.7.10-64bit-dbg-msvc12\\python_d.exe     #executable
: C:\\Python-2.7.10-64bit-dbg-msvc12\\include          #includes
: C:\\Python-2.7.10-64bit-dbg-msvc12\\libs             #libs
: <python-debugging>on ;

In order build a debug version of Boost, run bootstrap.bat first, then b2 with the following options:

b2 ^
--build-dir=build__64bit-dbg-msvc12 ^
--build-type=complete ^
--stagedir=stage__64bit-dbg-msvc12 ^
--user-config=my_config.bjam ^
address-model=64 ^
python-debugging=on ^
define=BOOST_PYTHON_DEBUG ^
define=BOOST_PYTHON_NO_LIB ^
link=shared ^
toolset=msvc-12.0 ^
variant=debug ^
stage

This should do the trick. You should define BOOST_PYTHON_DEBUG also when compiling the debug version of your program.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!