如何在VS2017中使用Boost Python库进行构建 [英] How to Build Using the Boost Python Libraries in VS2017

查看:233
本文介绍了如何在VS2017中使用Boost Python库进行构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MS Visual Studio Professional 2017和32位Python 3.4构建了Boost 1.64.0 Python库.现在,当我针对生成的库编写应用程序时,出现以下链接错误:

LINK:致命错误LNK1104:无法打开文件'libboost_python-vc141-mt-1_64.lib'

我查看了 stage/lib 目录,的确,该库名为 libboost_python 3 -vc141-mt-1_64.lib (请注意名称中的 3 ).我假设3引用的是Boost Python库是使用Python 3生成的事实.为什么在构建的库和我的项目尝试导入的库之间存在命名不一致的问题?这仅仅是我的项目配置中缺少的宏定义吗?

解决方案

在MSVC版本中,boost标头使用问题说明了如何为boost >.它可能会回答您有关构建的宏问题.

要解决此问题,您可以禁用自动链接,或直接重命名库文件以删除"3".

I have built the Boost 1.64.0 Python libraries, using MS Visual Studio Professional 2017 and 32-bit Python 3.4. Now, when I write an application against the resulting library, I'm getting the following link error:

LINK : fatal error LNK1104: cannot open file 'libboost_python-vc141-mt-1_64.lib'

I have looked in the stage/lib directory, and indeed, the library is named libboost_python3-vc141-mt-1_64.lib (note the 3 in the name). I'm assuming the 3 is referencing the fact that the Boost Python library was generated using Python 3. Why is there a naming inconsistency between the library that was built, and the library that my project is attempting to import? Is it simply a missing macro definition in my project configuration?

解决方案

In MSVC builds, the boost headers use MSVC #pragma comments to autolink to the boost libraries, see boost/config/auto_link.hpp.

In addition to including auto_link.hpp, the boost/python/detail/config.hpp file contains:

// Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it:
//
#define BOOST_LIB_NAME boost_python

Which is why MSVC is trying to autolink to libboost_python-vc141-mt-1_64.lib.

Clearly your boost build has built libboost_python3-vc141-mt-1_64.lib instead. As suggested by @kpie, your boost build may have named the python library file depending upon whether it's built for python 3 or python 2...

The answers to this question describes how to build boost for python 3. It may answer your macro question regarding the build.

To fix the issue, you could disable autolinking, or simply rename the library file to remove the "3".

这篇关于如何在VS2017中使用Boost Python库进行构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆