简体   繁体   English

与boost.python和python3的链接失败

[英]Trouble linking with boost.python and python3

When I attempt to compile a boost.python 'Hello World' program in Visual Studio 2017 on Win10, I run into the following link error: 当我尝试在Win10的Visual Studio 2017中编译boost.python'Hello World'程序时,遇到以下链接错误:

LNK1104 cannot open file 'boost_python-vc141-mt-1_64.lib'

However, I want to be linking with the python3 version. 但是,我想与python3版本链接。 I built my boost.python libraries with this command 我使用此命令构建了boost.python库

b2 --with-python variant=release link=shared address-model=64

with using python : 3.6 ; using python : 3.6 ; in my project-config.jam file, which produces 在我的project-config.jam文件中

boost_python3-vc141-mt-1_64.dll and boost_python3-vc141-mt-1_64.lib boost_python3-vc141-mt-1_64.dllboost_python3-vc141-mt-1_64.lib

I have no idea why my project is attempting to link with the python2 version. 我不知道为什么我的项目尝试与python2版本链接。 I never specified anywhere which boost.python library to link with, and I do not know where to change it. 我从未在任何地方指定要链接的boost.python库,也不知道在哪里更改它。

If it matters, here is the c++ program I am attempting to compile (into an x64 .dll) 如果重要的话,这是我尝试编译的C ++程序(转换为x64 .dll)

#include <boost/python.hpp>

char const* greet() {
    return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext) {
    using namespace boost::python;
    def("greet", greet);
}

In my experience, on Windows/VC++ Boost.Python's automatic linking always searches for boost_python-vc<blah-blah-blah>.lib regardless of Python version. 以我的经验,在Windows / VC ++上,Boost.Python的自动链接总是搜索boost_python-vc<blah-blah-blah>.lib而不管Python版本如何。 And when building against Python 3, b2 actually produces 2 sets of lib files: boost_python-vc... and boost_python3-vc... . 在针对Python 3进行构建时,b2实际上会生成2组lib文件: boost_python-vc...boost_python3-vc... They are identical, only names differ. 它们是相同的,只是名称不同。 So if you don't have boost_python-vc141-mt-1_64.lib file, rename your boost_python3-vc141-mt-1_64 lib and dll files by removing 3 . 因此,如果您没有boost_python-vc141-mt-1_64.lib文件,请通过删除3重命名您的boost_python3-vc141-mt-1_64 lib和dll文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM