【问题标题】:A linker error of Boost.Python in Visual Studio 2008Visual Studio 2008 中 Boost.Python 的链接器错误
【发布时间】:2014-11-24 13:54:44
【问题描述】:

我的英语很差,所以如果您尝试理解我的问题,我将不胜感激。



我已经安装了 Python3.3、Boost 1.50.0 和 Visual Studio 2008,它们都运行良好。

现在我想使用 Boost Python 库在 C++ 中嵌入 python 2.7.6,所以我下载了 Portable Python 2.7.6.1(来自portablepython.com/)。

我下载了 Boost lib。再次1.50.0,解压到另一个路径,按照构建教程编译。

一切似乎都很好,但是当我尝试编译我的代码时,我得到了一个链接器错误。

Error LNK1104 cannot open file 'python32.lib'

我不知道为什么它不是'python27.lib'

我很困惑,因为我从未安装过 Python3.2,并且我已经修改了 user-config.jam 以确保所有路径都已重定向到我的 Portable Python(2.7) 文件夹,并且新的 Boost 库已成功构建且没有错误。

几个星期以来我一直在尝试解决这个问题,使用了很多方法,但它仍然不起作用


我所做的所有事情都是:

  1. 下载 Boost C++ 库(来自 www.boost.org/users/history/version_1_50_0.html 的 boost_1_50_0.7z)

  2. 将它们解压到我的 boost 根路径(D:\Proj\ThirdPartyLib\boost_1_50_0)

  3. 下载Portable Python 2.7.6.1(来自portablepython.com/wiki/PortablePython2.7.6.1/)

  4. 将它们提取到 D:\Py27Test

  5. 修改user-config.jam,添加如下文本并保存到D:\Proj\ThirdPartyLib\boost_1_50_0\

    using python : 2.7 : "D:\Py27Test\App" : "D:\Py27Test\App\include" : "D:\Py27Test\App\libs" : ;

  6. 执行 Visual Studio 命令提示符 (x86)

    1. cd /D D:\Proj\ThirdPartyLib\boost_1_50_0
    2. bootstrap
    3. bjam --toolset=msvc-9.0 --python=2.7 --user-config=D:\Proj\ThirdPartyLib\boost_1_50_0\user-config.jam --debug-configuration

      调试信息是:

      notice: [python-cfg] Configuring python...

      notice: [python-cfg] user-specified version: "2.7"

      notice: [python-cfg] Checking interpreter command "python"...

      notice: [python-cfg] running command 'DIR /-C /A:S "D:\Py27Test\App\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: "D:\Py27Test\App\include"

      notice: [python-cfg] library path: "D:\Py27Test\App\libs"

      >notice: [python-cfg] DLL search path: "D:\Py27Test\App"

  7. 执行 Visual Studio 2008

    1. D:\Proj\ThirdPartyLib\boost_1_50_0添加到编译器包含路径
    2. D:\Proj\ThirdPartyLib\boost_1_50_0\stage\lib 添加到链接器库路径
  8. 创建测试代码:

#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>
#include <iostream>

int main(int argc, char** argv) {
     return 0;
}
  1. 编译代码,我会得到一个链接器错误(Error LNK1104 cannot open file 'python32.lib'

我错过了什么吗?

或者有没有人有任何想法来解决这个问题?

提前致谢

【问题讨论】:

  • 感谢您的通知。是的,我做到了,但我不知道在哪里可以找到 .lib 文件。我试图将 Python27.lib 重命名为 Python32.lib,但它不起作用(在运行时崩溃)。我搜索了名称“Python32.lib”,但找不到有关 32 位库的有用信息。

标签: python c++ visual-studio boost


【解决方案1】:

最后,我解决了这个问题。

  1. 将 D:\Py27Test\App\include 添加到编译器包含路径
  2. 将 D:\Py27Test\App\libs 添加到链接器库路径

似乎如果我不包含 Python.h,它将链接到默认库文件。 所以在我添加了这些路径之后,它现在可以工作了。

【讨论】:

    猜你喜欢
    • 2010-12-13
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多