簡體   English   中英

Boost.Python 1.54(調試版本)對Windows上的Python27.lib的依賴性令人費解

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

我必須犯一些明顯的錯誤,但經過數小時的戰斗,我無法取得進一步的進展:

升級(從稍早次要版本所有三個)升壓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"

我的機器上沒有任何其他Python安裝。

當我在我的項目上運行CMake時,一切看起來都很好:

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

Debug中鏈接器命令行的相關部分是預期的:

"C:\franz\dev\boost_1_54_0\stage\lib\libboost_python-vc110-mt-gd-1_54.lib" "C:\Python27\libs\python27_d.lib"

當我最終在Debug中構建項目時:

LINK : fatal error LNK1104: cannot open file 'python27.lib'

由於無處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") )。 問題仍然存在,但錯誤消息現在提到LINK : fatal error LNK1104: cannot open file 'python27_d.lib'

更新#3:使用進程監視器我可以在C:\\Python27\\libs\\中搜索C:\\Python27\\libs\\ ,它實際上駐留在:

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

更新#4 :相關問題: Visual C ++調試庫命名約定

我修復了這個問題,感謝這篇文章中的提示: Visual C ++調試庫命名約定

基本上,頭文件pyconfig.h附帶的Python(在C:\\Python27\\include\\ )的力量鏈接到python27_d.lib在調試版本(通過#pragma comment()指令),不管是否存在此庫或不。

訣竅是永遠不要直接包含Python.h ,而是包含Boost對該文件的包裝器, boost/python/detail/wrap_python.hpp負責禁用違規的#pragma comment()指令。

包括boost/python/detail/wrap_python.hpp而不是Python.h允許您使用Python的發行版本,即使在構建程序的調試版本時也是如此。

如果您自己編譯了Python的調試版本,則可以構建一個Boost的調試版本,該版本鏈接到您的調試版本的Python。 (我使用的是VS2013,但該過程應與VS2010和VS2012相同)。

首先創建一個名為my_config.bjam的文本文件:

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 ;

為了構建Boost的調試版本,首先運行bootstrap.bat ,然后使用以下選項運行b2

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

這應該可以解決問題。 在編譯程序的調試版本時,也應該定義BOOST_PYTHON_DEBUG

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM