【发布时间】: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 Python 和 this Python howto from Boost 的说明进行操作,但由于这两个链接都有些过时,做事方式不同,而且某些步骤似乎在新版本的 Boost 中发生了变化,我不得不即兴发挥在一些说明上。
这就是我所做的。
- 将最新版本 (1.55) 的 Boost 源文件解压到
C:\boost_1_55_0。 - 使用
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。 - 在 cmd 中使用
bootstrap。 - 编辑了
project-config.jam(由bootstrap创建)并添加了我的Python 3.4 安装路径C:\Python34。我的.jam文件现在看起来如 Project-Config.jam 中所示。 - 在 cmd 中使用
.\b2来启动构建过程。虽然我在构建过程中收到了很多警告(forcing value to bool 'true' or 'false' (performance warning)等),但构建完成后似乎没有任何错误消息。
包括
这就是我在 Visual Studio 中创建项目的方式。
- 创建了一个新项目。
- 添加了测试代码中的代码。
- 在项目属性中的 VC++ 目录下:
- 已将
C:\boost_1_55_0添加到Include Directories。 - 将
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>c:\python\python34\include\pymath.h(22): warning C4273: 'round' : inconsistent dll linkage所以也许我还是做错了什么。
标签: python c++ visual-studio boost boost-python