使用 python3 为 msvc 构建 boost python - 链接器错误

Building boost python for msvc with python3 - Linker Error

本文关键字:链接 错误 python boost python3 msvc 构建 使用      更新时间:2023-10-16

我正在将Python Libary从python 2.7移植到3.6,在全新安装的Win10上,VS2013和Anaconda Python 3.6 64位。

库包含一个dll,它使用boost python作为python的包装器,所以我必须重新编译它。 由于之前的 boost 库是针对 python 2.7 编译的,我再次从一个新的boost_1_63_0开始,并在project-config.jam中使用以下设置对其进行编译

import option ;    
using msvc = 12.0;  
using python : 3.6 : C:\ProgramData\Anaconda3 ;   
option.set keep-going : false ;

使用这些参数

bjam.exe --with-python address-model=64 variant=release link=shared
--build-type=complete

我得到了一整套编译的库:

└───lib
boost_numpy36-vc120-mt-x64-1_67.dll
boost_numpy36-vc120-mt-x64-1_67.lib
boost_python36-vc120-mt-x64-1_67.dll
boost_python36-vc120-mt-x64-1_67.lib
...
libboost_python36-vc120-mt-gd-x32-1_67.lib
libboost_python36-vc120-mt-gd-x64-1_67.lib
libboost_python36-vc120-mt-x32-1_67.lib
libboost_python36-vc120-mt-x64-1_67.lib
...
libboost_numpy36-vc120-mt-gd-x32-1_67.lib
libboost_numpy36-vc120-mt-gd-x64-1_67.lib
libboost_numpy36-vc120-mt-x32-1_67.lib
libboost_numpy36-vc120-mt-x64-1_67.lib

由于我在链接器方面遇到了一些问题,我在Visual Studio中启动了一个新的Soulution。所需的 boost 和 Pyton 文件夹已添加到项目 C/C++-->general-->附加包含目录中,并且 boost 的stagelibs文件夹和 python 的libs文件夹已添加到链接器的其他库目录中。

我尝试编译下面的最小示例,该示例在我的其他系统上完美运行,该系统仍在基于 python 2.7 的旧 boost 版本上运行:

#include "stdafx.h"
#define BOOST_PYTHON_STATIC_LIB  
#define BOOST_LIB_NAME "boost_numpy"
#include <boost/config/auto_link.hpp>
#include <boost/python/numpy.hpp>
#include <boost/python.hpp>
#include <boost/python/numpy.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>

编译时出现以下链接器错误

LNK1104: cannot open file 'libboost_numpy-vc120-mt-x64-1_67.lib'

因此,出于某种原因,构建创建了一个名为boost_numpy36-vc120-mt-x64-1_67.lib的库,但链接器仍在搜索没有 python 版本36的版本。

当我简单地从库中删除python版本时,我得到以下链接器错误:

LNK1104: cannot open file 'libboost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc120-mt-gd-x32-1_67.lib'

知道这里发生了什么吗?

[更新]

好的,所以在找到这个问题后,我意识到该名称与BOOST_LIB_NAME的定义相关联,所以我将其更改为

#define BOOST_LIB_NAME "boost_numpy36"

但不幸的是,我仍然收到第二个链接错误:

LNK1104: cannot open file 'libboost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc120-mt-gd-x32-1_67.lib'

我无法解决描述错误,但我在这里找到了一组预编译的库: https://www.lfd.uci.edu/~gohlke/pythonlibs/

你提到的问题:

LNK1104:无法打开文件 'libboost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-VC120-MT-GD-x32-1_67.lib'

在此提交中已解决。

要获得问题的完整上下文,您可以检查此内容