简体   繁体   English

Windows / MSVC10下的Boost.Python链接错误

[英]Boost.Python link errors under Windows/MSVC10

I compiled the boost 1.50.0 libraries using b2 with the correct Python configuration. 我使用正确的Python配置使用b2编译了boost 1.50.0库。 Here's the relevant ouput from the command b2 --debug-configuration : 这是命令b2 --debug-configuration的相关输出:

notice: [python-cfg] Configuring python...
notice: [python-cfg]   user-specified cmd-or-prefix: "C:\Python33z\python"
notice: [python-cfg] Checking interpreter command "C:\Python33z\python"...
notice: [python-cfg] running command 'DIR /-C /A:S "C:\Python33z\python.exe" 2>&
1'
notice: [python-cfg] running command '"C:\Python33z\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] Configuring python...
notice: [python-cfg]   user-specified cmd-or-prefix: "C:\Python33z\python"
notice: [python-cfg] Checking interpreter command "C:\Python33z\python"...
notice: [python-cfg] running command 'DIR /-C /A:S "C:\Python33z\python.exe" 2>&
1'
notice: [python-cfg] running command '"C:\Python33z\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: "C:\Python33z\python"
notice: [python-cfg]   include path: "C:\Python33z\Include"
notice: [python-cfg]   library path: "C:\Python33z\libs"
notice: [python-cfg]   DLL search path: "C:\Python33z"
notice: [msvc-cfg] msvc-10.0 detected, command: 'C:\Program Files (x86)\Microsof
t Visual Studio 10.0\VC\bin\cl.exe'
notice: will use 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.
exe' for msvc, condition <toolset>msvc-10.0

...updating 4 targets...
msvc.archive bin.v2\libs\python\build\msvc-10.0\debug\link-static\threading-mult
i\libboost_python3-vc100-mt-gd-1_50.lib
common.copy stage\lib\libboost_python3-vc100-mt-gd-1_50.lib
bin.v2\libs\python\build\msvc-10.0\debug\link-static\threading-multi\libboost_py
thon3-vc100-mt-gd-1_50.lib
        1 file(s) copied.
msvc.archive bin.v2\libs\python\build\msvc-10.0\release\link-static\threading-mu
lti\libboost_python3-vc100-mt-1_50.lib
common.copy stage\lib\libboost_python3-vc100-mt-1_50.lib
bin.v2\libs\python\build\msvc-10.0\release\link-static\threading-multi\libboost_
python3-vc100-mt-1_50.lib
        1 file(s) copied.
...updated 4 targets...


The Boost C++ Libraries were successfully built!

I have set the linker directories correctly and linked to the appropriate output files ( libboost_ python3-vc100-mt-1_50.lib on release, and libboost_python3-vc100-mt-gd-1_50.lib on debug). 我已正确设置链接器目录并链接到相应的输出文件(发布时为libboost_ python3-vc100-mt-1_50.liblibboost_python3-vc100-mt-gd-1_50.lib )。 I am using a self compiled python distribution, but I've tried with the standard ones too and the result isn't any different. 我正在使用自编译的python发行版,但我也尝试过标准的发行版,结果没有任何不同。

The link errors I'm getting when I compile are: 我编译时遇到的链接错误是:

error LNK2019: unresolved external symbol "__declspec(dllimport) protected: __thiscall boost::python::detail::str_base::str_base(char const *)" (__imp_??0str_base@detail@python@boost@@IAE@PBD@Z) referenced in function "public: __thiscall boost::python::str::str(char const *)" (??0str@python@boost@@QAE@PBD@Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::detail::str_base::~str_base(void)" (__imp_??1str_base@detail@python@boost@@QAE@XZ) referenced in function "public: __thiscall boost::python::str::~str(void)" (??1str@python@boost@@QAE@XZ)
error LNK2019: unresolved external symbol "__declspec(dllimport) class boost::python::api::object __cdecl boost::python::import(class boost::python::str)" (__imp_?import@python@boost@@YA?AVobject@api@12@Vstr@12@@Z) referenced in function _main
fatal error LNK1120: 3 unresolved externals

The test code which produced those errors boils down to: 产生这些错误的测试代码归结为:

using namespace boost::python;
object main_module = import("__main__");

I have used Boost.Filesystem with the same build configuration and it didn't cause me any problems. 我使用了具有相同构建配置的Boost.Filesystem ,它没有给我带来任何问题。

I hope somebody can help me with this issue, it's really confusing me! 我希望有人可以帮我解决这个问题,这真让我感到困惑!

Update : I just read some vague text about the define BOOST_PYTHON_STATIC_LIB ; 更新我刚读了一些关于定义BOOST_PYTHON_STATIC_LIB模糊文本 ; i'm not sure if i'm headed in the right direction with this (since afaik it wasn't mentioned in the build process), but either way, it gives me an even more confusing error: 我不确定我是否朝着正确的方向前进(因为afaik在构建过程中没有提到),但不管怎样,它给了我一个更令人困惑的错误:

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

I don't know why it trys to link with that lib when the python-cfg output clearly shows it found my python33 dist (which my application is already linking with; python33.lib). 当python-cfg输出清楚地显示它发现我的python33 dist(我的应用程序已经链接了; python33.lib)时,我不知道为什么它试图链接到那个lib。

First problem: It turns out defining BOOST_PYTHON_STATIC_LIB was indeed the correct way to fix the unresolved external link errors. 第一个问题:事实证明定义BOOST_PYTHON_STATIC_LIB确实是修复未解决的外部链接错误的正确方法。 It appears to be a necessary define when linking with the static lib; 当与静态lib链接时,它似乎是必要的定义; this seems obvious, but it is not mentioned here: http://www.boost.org/doc/libs/1_50_0/libs/python/doc/building.html . 这似乎很明显,但这里没有提到: http//www.boost.org/doc/libs/1_50_0/libs/python/doc/building.html

Second problem: After adding that define, the next link error happened because I didn't run b2 clean before re-building with the correct Python configuration (ie. nothing was re-compiled until cleaned!), this should have been obvious from the lack of compiler related output, but it did fool me, so it's just another little thing to look out for. 第二个问题:在添加了这个定义之后,发生了下一个链接错误,因为我在使用正确的Python配置重新构建之前没有运行b2 clean (即,在b2 clean之前没有重新编译!),这应该是显而易见的缺乏编译器相关的输出,但它确实欺骗了我,所以这只是另一件小事需要注意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM