如何在VS2017中使用Boost Python库进行构建

编程入门 行业动态 更新时间:2024-10-10 19:19:03
本文介绍了如何在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标头使用 MSVC #pragma注释到autolink到boost库,请参见boost/config/auto_link.hpp.

除了包含auto_link.hpp,boost/python/detail/config.hpp文件还包含:

// 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

这就是为什么MSVC试图将autolink转换为libboost_python-vc141-mt-1_64.lib的原因.

很显然,您的boost构建已构建了libboost_python3-vc141-mt-1_64.lib.正如@kpie所建议的那样,您的boost构建可能已命名python库文件,具体取决于它是为python 3还是python 2构建的.

对此问题的答案此问题说明了如何为.它可能会回答您有关构建的宏问题.

要解决此问题,您可以禁用自动链接,或直接重命名库文件以删除"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库进行构建

本文发布于:2023-11-16 01:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1599936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Python   Boost

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!