Windows/MSVC10下的Boost.Python链接错误
Boost.Python link errors under Windows/MSVC10
我使用正确的Python配置使用b2编译了boost 1.50.0库。以下是命令b2 --debug-configuration
的相关输出:
notice: [python-cfg] Configuring python...
notice: [python-cfg] user-specified cmd-or-prefix: "C:Python33zpython"
notice: [python-cfg] Checking interpreter command "C:Python33zpython"...
notice: [python-cfg] running command 'DIR /-C /A:S "C:Python33zpython.exe" 2>&
1'
notice: [python-cfg] running command '"C:Python33zpython" -c "from sys import
*; print('version=%d.%dnplatform=%snprefix=%snexec_prefix=%snexecutable=%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:Python33zpython"
notice: [python-cfg] Checking interpreter command "C:Python33zpython"...
notice: [python-cfg] running command 'DIR /-C /A:S "C:Python33zpython.exe" 2>&
1'
notice: [python-cfg] running command '"C:Python33zpython" -c "from sys import
*; print('version=%d.%dnplatform=%snprefix=%snexec_prefix=%snexecutable=%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:Python33zpython"
notice: [python-cfg] include path: "C:Python33zInclude"
notice: [python-cfg] library path: "C:Python33zlibs"
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.0VCbincl.exe'
notice: will use 'C:Program Files (x86)Microsoft Visual Studio 10.0VCbincl.
exe' for msvc, condition <toolset>msvc-10.0
...updating 4 targets...
msvc.archive bin.v2libspythonbuildmsvc-10.0debuglink-staticthreading-mult
ilibboost_python3-vc100-mt-gd-1_50.lib
common.copy stageliblibboost_python3-vc100-mt-gd-1_50.lib
bin.v2libspythonbuildmsvc-10.0debuglink-staticthreading-multilibboost_py
thon3-vc100-mt-gd-1_50.lib
1 file(s) copied.
msvc.archive bin.v2libspythonbuildmsvc-10.0releaselink-staticthreading-mu
ltilibboost_python3-vc100-mt-1_50.lib
common.copy stageliblibboost_python3-vc100-mt-1_50.lib
bin.v2libspythonbuildmsvc-10.0releaselink-staticthreading-multilibboost_
python3-vc100-mt-1_50.lib
1 file(s) copied.
...updated 4 targets...
The Boost C++ Libraries were successfully built!
我已经正确设置了链接器目录,并链接到适当的输出文件(发布时为libboost_
python3-vc100-mt-1_50.lib
,调试时为libboost_python3-vc100-mt-gd-1_50.lib
)。我使用的是自编译的python发行版,但我也尝试过标准版本,结果没有什么不同。
当我编译时,我得到的链接错误是:
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
产生这些错误的测试代码可以归结为:
using namespace boost::python;
object main_module = import("__main__");
我使用了具有相同构建配置的Boost.Filesystem
,它没有给我带来任何问题。
我希望有人能帮我解决这个问题,这真的让我困惑!
更新:我刚刚读到一些关于定义BOOST_PYTHON_STATIC_LIB
的模糊文本;我不确定我是否朝着正确的方向前进(因为afaik在构建过程中没有提到它),但不管怎样,它都给了我一个更令人困惑的错误:
LINK : fatal error LNK1104: cannot open file 'python27.lib'
我不知道当python cfg输出清楚地显示它找到了我的python33 dist(我的应用程序已经与之链接;python33.lib)时,它为什么要尝试与该lib链接。
第一个问题:事实证明,定义BOOST_PYTHON_STATIC_LIB
确实是修复未解决的外部链接错误的正确方法。当与静态库链接时,它似乎是一个必要的定义;这似乎很明显,但这里提到的是而不是:http://www.boost.org/doc/libs/1_50_0/libs/python/doc/building.html.
第二个问题:添加该定义后,下一个链接错误发生了,因为我在使用正确的Python配置重新构建之前没有运行b2 clean
(即,在清理之前没有重新编译任何内容!),这应该从缺乏编译器相关的输出中显而易见,但它确实欺骗了我,所以这只是另一件需要注意的小事。
- 使用转换器提升 Python 问题 - 静态链接
- 静态链接 glibc & boost_python36 for Python extension
- 编译时出现Boost.python链接错误
- Boost Python 不断链接 Python27 库
- 使用 python3 为 msvc 构建 boost python - 链接器错误
- 与 boost.python 和 python3 链接时出现问题
- 将 c++ 与 python 链接起来
- 链接boost.python示例的问题
- 使用Tensorflow/Bazel从C++调用Python时出现链接错误
- 嵌入C++时如何链接正确的python版本?
- SWIG - C ++到Python.链接系统库
- 在 Python-C++-C-Fortran 2003 程序中链接英特尔的 MKL
- 针对boost python进行链接会在PyCEGUI中产生未定义的引用
- Java/Python在C/C++中访问的动态链接库
- 使用 boost python 进行静态链接
- 在 python 中使用链接库中的方法时出现属性错误
- 如何在Qt Designer(Python)中创建弹出窗口(将主窗口与对话框链接)
- Boost.Python 快速入门链接器错误
- Windows/MSVC10下的Boost.Python链接错误
- python链接列表指针和大小