Boost.Python 1.54(调试版本)对Windows上的Python27.lib的依赖性令人费解

Fra*_*une 4 c++ boost cmake boost-python visual-c++

我必须犯一些明显的错误,但经过数小时的战斗,我无法取得进一步的进展:

升级到(所有三个升压1.54,CMake的2.8.12和Python 2.7.5后小幅早期次要版本),我的Python绑定项目在调试配置不再联系(他们释放联接罚款).我正在使用VS 2012构建.在更新之前一切正常.

我用标准的方式构建了Boost:bootstrap.bat接下来b2 address-model=64 toolset=msvc-11.0.我的系统有一个Python 2.7安装,由b2选择:

notice: [python-cfg] Configuring python...
notice: [python-cfg] Registry indicates Python 2.7 installed at "C:\Python27\"
notice: [python-cfg] Checking interpreter command "python"...
notice: [python-cfg] running command 'DIR /-C /A:S "C:\Python27\python.exe" 2>&1'
notice: [python-cfg] running command 'python -c "from sys import *; print('version=%d.%d\nplatform=%s\nprefix=%s\nexec_prefix=%s\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))" 2>&1'
notice: [python-cfg] ...requested configuration matched!
notice: [python-cfg] Details of this Python configuration:
notice: [python-cfg]   interpreter command: "python"
notice: [python-cfg]   include path: "C:\Python27\Include"
notice: [python-cfg]   library path: "C:\Python27\libs"
notice: [python-cfg]   DLL search path: "C:\Python27"
Run Code Online (Sandbox Code Playgroud)

我的机器上没有任何其他Python安装.

当我在我的项目上运行CMake时,一切看起来都很好:

Found PythonLibs: optimized;C:/Python27/libs/python27.lib;debug;C:/Python27/libs/python27_d.lib (found version "2.7.5")
Run Code Online (Sandbox Code Playgroud)

Debug中链接器命令行的相关部分是预期的:

"C:\franz\dev\boost_1_54_0\stage\lib\libboost_python-vc110-mt-gd-1_54.lib" "C:\Python27\libs\python27_d.lib"
Run Code Online (Sandbox Code Playgroud)

当我最终在Debug中构建项目时:

LINK : fatal error LNK1104: cannot open file 'python27.lib'
Run Code Online (Sandbox Code Playgroud)

由于python27.lib在链接器的命令行中没有提到,我libboost_python-vc110-mt-gd-1_54.lib只使用十六进制编辑器进行编辑,以发现它包含对python27.lib(/DEFAULTLIB:"python27.lib"我希望引用的)形式的引用python27_d.lib(其中没有引用).

我在构建Boost时做错了什么?这是Boost 1.54中Boost.Python的已知问题吗?任何帮助将不胜感激.


更新#1:我再次尝试使用Boost 1.51和1.50并出现同样的问题,因此它不是Boost中的回归.

更新#2:我从Python安装中删除了Python lib(python27_d.lib)的调试版本,从而恢复为vanilla Python安装.然后我重建了Boost 1.51和我的项目(CMake按预期报告了一个库文件:) Found PythonLibs: C:/Python27/libs/python27.lib (found version "2.7.5").问题仍然存在,但是错误消息现在提到python27_d.lib: LINK : fatal error LNK1104: cannot open file 'python27_d.lib'!

更新#3:使用进程监视器我可以在C:\Python27\libs\实际驻留的位置搜索python27_d.lib :

3:35:28.0550683 PM  link.exe    10132   CreateFile  C:\franz\dev\appleseed\build\appleseed.python\python27_d.lib    NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:35:28.0551846 PM  link.exe    10132   CreateFile  C:\franz\dev\boost_1_50_0\stage\lib\python27_d.lib  NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:35:28.0552474 PM  link.exe    10132   CreateFile  C:\franz\dev\boost_1_50_0\stage\lib\Debug\python27_d.lib    PATH NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:35:28.0553595 PM  link.exe    10132   CreateFile  C:\franz\dev\appleseed\build\appleseed.python\python27_d.lib    NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:35:28.0556105 PM  link.exe    10132   CreateFile  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\python27_d.lib NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:35:28.0559637 PM  link.exe    10132   CreateFile  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\lib\amd64\python27_d.lib  NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:35:28.0560984 PM  link.exe    10132   CreateFile  C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64\python27_d.lib  NAME NOT FOUND  Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a
3:35:28.0561741 PM  link.exe    10132   CreateFile  C:\franz\dev\appleseed\build\appleseed.python\python27_d.lib    NAME NOT FOUND  Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: n/a, ShareMode: Read, AllocationSize: n/a
Run Code Online (Sandbox Code Playgroud)

更新#4:相关问题:Visual C++调试库命名约定

Fra*_*une 9

我修复了这个问题,感谢这篇文章中的提示:Visual C++调试库命名约定.

基本上,pyconfig.hPython(in C:\Python27\include\)附带的头文件强制链接到python27_d.libDebug构建(通过#pragma comment()指令),无论该库是否存在.

诀窍是永远不要Python.h直接包含,而是包含Boost的该文件包装器,boost/python/detail/wrap_python.hpp它负责禁用违规#pragma comment()指令.