Visual Studio 2008 中 Boost.Python 的链接器错误

A linker error of Boost.Python in Visual Studio 2008

本文关键字:链接 错误 Python Boost Studio 2008 Visual      更新时间:2023-10-16

我的英语很差,所以如果你试着理解我的问题,我将不胜感激.


我安装了Python3.3,Boost 1.50.0和Visual Studio 2008,它们都可以正常工作><。现在我想通过使用 Boost Python 库在 C++ 中嵌入 python 2.7.6,所以我下载了可移植的 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 以确保所有路径都已重定向到我的可移植 Python(2.7) 文件夹,并且新的 Boost 库已成功构建,没有错误.
几周来,我一直在尝试解决问题,使用多种方法,但仍然不起作用


我所做的所有事情都是:

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

  2. 将它们解压缩到我的提升根路径(D:\Proj\第三方库\boost_1_50_0

  3. 下载可移植的Python 2.7.6.1(从 portablepython.com/wiki/PortablePython2.7.6.1/)

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

  5. 修改user-config.jam,添加以下文本并将其保存到 D:\Proj\第三方库\boost_1_50_0\

    using python : 2.7 : "D:Py27TestApp" : "D:Py27TestAppinclude" : "D:Py27TestApplibs" : ;

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

    1. cd /D D:ProjThirdPartyLibboost_1_50_0
    2. bootstrap


    3. bjam --toolset=msvc-9.0 --python=2.7 --user-config=D:ProjThirdPartyLibboost_1_50_0user-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:Py27TestApppython.exe" 2>&1'
      notice: [python-cfg] running command '"python" -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: "python"

      notice: [python-cfg] include path: "D:Py27TestAppinclude"
      notice: [python-cfg] library path: "D:Py27TestApplibs"

      notice: [python-cfg] DLL search path: "D:Py27TestApp"

  7. 执行 Visual Studio 2008

    1. D:\Proj\第三方库\boost_1_50_0添加到编译器包含路径
    2. D:\Proj\第三方库\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. 遵守代码,我会得到一个链接器错误(错误LNK1104无法打开文件"python32.lib")

我错过了什么吗?
或者有人有任何想法来解决这个问题吗?
提前致谢

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

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

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