python - Windows VS 中的 Boost numpy 链接器错误

标签 python visual-studio numpy boost

我正在使用 Boost 1.64 和 Visual Studio 来创建 Python 模块。具体来说,我使用 Boost Numpy 模块来处理模块中的 numpy 数组。

我使用以下命令编译了 Boost:

b2 -j8  address-model=32  --user-config=D:\code\libraries\boost_1_64_0\user-config.jam --with-python   --build-type=complete stage --stagedir=stage/win32

在我的代码中,我添加了静态链接定义(我读过的所有帖子似乎都需要它):#define BOOST_PYTHON_STATIC_LIB

当我编译代码时发生了两件奇怪的事情:

1) 当使用诊断定义 (#define BOOST_LIB_DIAGNOSTIC) 时,它显示编译器链接到 python 库的静态版本,但链接到 numpy 库的动态版本:

  • 链接到 lib 文件:libboost_python-vc141-mt-1_64.lib
  • 链接到 lib 文件:boost_numpy-vc141-mt-1_64.lib

当我禁用自动链接并自己添加正确的库时,我最终收到 Unresolved 链接器错误:

error LNK2001: unresolved external symbol "class boost::python::numpy::dtype __cdecl boost::python::numpy::detail::get_float_dtype<32>(void)" (??$get_float_dtype@$0CA@@detail@numpy@python@boost@@YA?AVdtype@123@XZ)

奇怪的是,这个错误只会在使用 numpy 中使用模板的函数时抛出!我实际上可以运行使用 boost_numpy 库的代码,该库不使用模板函数,并且它将链接并运行良好! 有谁知道为什么基于模板的函数会抛出此链接器错误? 非常感谢任何帮助!

H

最佳答案

我通过添加以下内容修复了链接器错误:

#define BOOST_NUMPY_STATIC_LIB

所以我的序言现在是:

  1. #define BOOST_PYTHON_STATIC_LIB
  2. #define BOOST_NUMPY_STATIC_LIB

错误就消失了。

H

关于python - Windows VS 中的 Boost numpy 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45069253/

相关文章:

numpy - &vs *和| vs +

python - django save() 禁止,以防止因未保存相关对象而导致数据丢失

windows - Windows 如何知道 .sln 文件与哪个版本的 Visual Studio 相关?

c# - 如何使用 MSBuild 注册一个 dll

python - 从技术上讲,numpy.mgrid 是什么?

使用通用函数的 Python numpy 网格转换

python - 如何生成嵌入图表的 Excel 电子表格?

python - 旧 python 版本的 SSL 上下文

Python嵌套列表(二维数组)引用

visual-studio - 为什么我的 Visual Studio 2019 Pro 在执行 Visual Installer 更新后调试如此缓慢?