【问题标题】:Building/including Boost.Python in VS2013在 VS2013 中构建/包含 Boost.Python
【发布时间】:2014-07-08 22:13:30
【问题描述】:

如果我做错了什么,谁能告诉我。

我在 Windows 7 上使用 Visual Studio 2013,我希望能够设置一个简单的 Boost.Python 项目。我不知道我是否在构建 boost 或在我的项目中包括 boost 时做错了什么。

错误

当我尝试#include 任何 boost python 模块时,例如#include <boost/python/module.hpp> 我在 Visual Studio 中收到以下错误。

1>c:\boost_1_55_0\boost\python\detail\wrap_python.hpp(50): fatal error C1083: Cannot open include file: 'pyconfig.h': No such file or directory

建筑

我尝试按照 this SO thread in which KTC addresses Pythonthis Python howto from Boost 的说明进行操作,但由于这两个链接都有些过时,做事方式不同,而且某些步骤似乎在新版本的 Boost 中发生了变化,我不得不即兴发挥在一些说明上。

这就是我所做的。

  1. 将最新版本 (1.55) 的 Boost 源文件解压到 C:\boost_1_55_0
  2. 使用cmd.exe 导航到C:\boost_1_55_0。 (我没有使用在\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts 下找到的Developer Command Prompt for VS2013。这应该没什么区别,不是吗?Boosts official guide for 1.55 没有具体提到使用Command Prompt for VS2013
  3. 在 cmd 中使用 bootstrap
  4. 编辑了project-config.jam(由bootstrap 创建)并添加了我的Python 3.4 安装路径C:\Python34。我的.jam 文件现在看起来如 Project-Config.jam 中所示。
  5. 在 cmd 中使用 .\b2 来启动构建过程。虽然我在构建过程中收到了很多警告(forcing value to bool 'true' or 'false' (performance warning) 等),但构建完成后似乎没有任何错误消息。

包括

这就是我在 Visual Studio 中创建项目的方式。

  1. 创建了一个新项目。
  2. 添加了测试代码中的代码。
  3. 在项目属性中的 VC++ 目录下:
    1. 已将C:\boost_1_55_0 添加到Include Directories
    2. C:\boost_1_55_0\stage\lib(我可以在其中找到.lib 文件的文件夹)添加到Library Directories

Project-Config.jam

import option ; 

using msvc ; 

option.set keep-going : false ; 

using python : 3.4 : C:\\Python34\\python ;

测试代码

发件人:boost_1_55_0\libs\python\example\getting_started1.cpp

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <string>

namespace 
{ 
    // A couple of simple C++ functions that we want to expose to Python.
    std::string greet() { return "hello, world"; }
    int square(int number) { return number * number; }
}

namespace python = boost::python;

BOOST_PYTHON_MODULE(getting_started1)
{
    // Add regular functions to the module.
    python::def("greet", greet);
    python::def("square", square);
}

【问题讨论】:

  • 我有这个用于 python,注意多个包含目录:using python : 3.5 : D:\\temp\\python\\PCbuild\\python.exe # cmd-or-prefix : D:\\temp\\python\\include D:\\temp\\cpythonorig\\PC : D:\\temp\\python\\PCbuild ;
  • using python : 3.4 : C:\\Python34\\python ; -- 拖尾\\python 不是多余的吗?
  • @UlrichEckhardt 你这么认为吗?我不会知道的。我刚刚从KTC's post in this tread 复制了它。但我会很高兴任何能帮助我发现错误的东西。据了解,我的项目似乎正在运行,但我有一个警告我无法摆脱,1&gt;c:\python\python34\include\pymath.h(22): warning C4273: 'round' : inconsistent dll linkage 所以也许我还是做错了什么。

标签: python c++ visual-studio boost boost-python


【解决方案1】:

看来我只需要在我的包含和库依赖项中添加Python34/include/Python34/libs/ 的路径。

【讨论】:

  • 谢谢你,它帮了很多忙!给未来访问者的注意事项,最好的方法是使用 PYTHONPATH 环境变量,就像在 this answer 中一样,而不是单独添加每个目录。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-28
  • 1970-01-01
  • 2016-03-12
  • 2017-01-15
  • 2017-05-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多