链接到 Boost python 3.6.找不到 boost_python 而不是 boost_python3

2022-01-11 00:00:00 python visual-studio-2017 linker c++ boost

我在链接 boost python 时遇到问题.

I have problems linking against boost python.

我正在使用 Visual Studio 2017 并使用以下命令行编译了 boost 1_64 包:

I am using Visual Studio 2017 and compiled the boost 1_64 package with the following command line:

b2 -a toolset=msvc-14.1 --build_type=complete stage variant=debugthreading=multi link=shared runtime-link=shared define=_ITERATOR_DEBUG_LEVEL=0 address-model=64

使用这个 user-config.jam:

with this user-config.jam:

using python 
: 3.6                   # Version
: C:\Python36\python.exe      # Python Path
: C:\Python36\include         # include path
: C:\Python36\libs            # lib path(s)
: <define>BOOST_ALL_NO_LIB=1
;

但是在使用运行时库构建我的 c++ 项目时:多线程 DLL (/MD) 我不断收到此错误消息:

But while building my c++ project with runtime libary: Multi-threaded DLL (/MD) I keep getting this error message:

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

但我编译的 boost 库包含以下 boost_python 文件:

but the boost libs I compiled contain the following boost_python files:

boost_python3-vc141-mt-gd-1_64.dll
boost_python3-vc141-mt-gd-1_64.lib

有人对 python 3 的 boost 有经验吗?经过数小时的尝试,我找不到一个好的解决方案.顺便说一句:将文件重命名为 boost_python- (删除 3)工作正常.但我不认为这是正确的方法

Does someone have experience with boost for python 3? After hours of trying, I can't find a good solution. Btw.: renaming the files to boost_python- (removing the 3) works fine. But I don't think that this is the correct way

VC 项目设置:

添加.包含目录:

C:Python36include;D:wsoost_1_64_0oost_1_64_0;

添加.库目录:

D:wsoost_1_64_0oost_1_64_0stagelib;C:Python36libs;

<小时>

已关闭:boost 的自动链接功能在 python 3 中无法正常工作.boost_module_name 宏设置为 boost_python(缺少 3),并且生成的库包含 3.


Closed: The autolink feature of boost did not work correctly with python 3. The boost_module_name macro was set to boost_python (missing the 3) and the generated libs contained the 3.

--> 关闭自动链接并手动添加所需的库.

--> Turned auto link off and added the required libs manually.

解决方案a) 转到 boost/python/detail/config.hpp 并将 BOOST_LIB_NAMe 更改为 boost_python3 而不是 boost_python.

Solution a) Go to boost/python/detail/config.hpp and change BOOST_LIB_NAMe to boost_python3 instead of boost_python.

解决方案b) 通过定义 BOOST_ALL_NO_LIB 开启自动链接,然后显式设置 boost_python3...lib 作为链接器依赖.

Solution b) Turn auto Linkage of by defining BOOST_ALL_NO_LIB and then explicitly set boost_python3...lib as linker dependency.

推荐答案

抱歉来晚了,我自己也经历了同样的废话.结果证明 boost 不能很好地处理两次安装(甚至是 py3.x 本身)

Sorry for coming in late here, just went through the same nonsense myself. Turns out that boost doesn't handle two installs very well (or even a py3.x by itself)

您绝对可以通过进入 <boost/python/detail/config.hpp> 并进行快速更改来解决这个问题.为了让 boost 同时适用于 python 2.x(大概是 2.7)和 3.x,我建议更改:

You can definitely solve this by going into <boost/python/detail/config.hpp> and making a quick change. To allow for boost to work with both python 2.x (2.7, presumably) and 3.x, I'd suggest changing:

#define BOOST_LIB_NAME boost_python

#if PY_MAJOR_VERSION >=3
  #define BOOST_LIB_NAME boost_python3
#else
  #define BOOST_LIB_NAME boost_python
#endif

相关文章