2014-05-20 23 views
8

有人可以告诉我我是否做错了什么。建筑/包括VS2013中的Boost.Python

我在使用Visual Studio 2013的Windows 7上,我希望能够设置一个简单的Boost.Python项目。我不知道我是否犯了错误建设提升或当包括在我的项目提振。

错误

当我尝试#include任何升压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. 将Boost源文件的最新版本(1.55)解压缩到C:\boost_1_55_0
  2. 使用cmd.exe导航到C:\boost_1_55_0。 (我没有使用Developer Command Prompt for VS2013\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts下找到。这是不应该有任何区别,应该吗?Boosts official guide for 1.55没有做出使用Command Prompt for VS2013的任何具体提及。
  3. 在cmd中使用bootstrap
  4. 编辑project-config.jam(由bootstrap创建),并添加路径我的Python 3.4安装C:\Python34。我.jam文件现在看起来像在项目 - 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_0Include Directories
    2. 添加了C:\boost_1_55_0\stage\lib(我能找到.lib文件的文件夹)到Library Directories

项目 - 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); 
} 
+0

我有这个的蟒蛇,注意多include目录:'使用python :3.5 :d:\\ \\温度蟒蛇\\ \\ PCbuild#python.exe CMD-或前缀 :d:\ \ temp \\ python \\ include D:\\ temp \\ cpythonorig \\ PC :D:\\ temp \\ python \\ PCbuild;' – stijn

+0

'using python:3.4:C:\\ Python34 \\ python; ' - 不是拖尾的'\\ python'多余的? –

+0

@UlrichEckhardt你这么认为?我不知道。我只是从[KTC的帖子中复制它]复制它(http://stackoverflow.com/questions/2629421/how-to-use-boost-in-visual-studio-2010/2655683#2655683)。但是我会很高兴能够帮助我发现错误。我的项目似乎正在工作,但我有一个警告,我无法摆脱,'1> c:\ python \ python34 \ include \ pymath.h(22):warning C4273:'round':inconsistent DLL连接“,所以也许我仍然做错了什么。 – Adelost

回答

10

看来我只是需要在我的包含和库依赖关系中添加一个路径到Python34/include/Python34/libs/

+1

谢谢你的帮助!对未来访问者来说,最好的方法是使用'PYTHONPATH'环境变量,就像在[这个答案](http://stackoverflow.com/a/4855685/3524982)中一样,而不是单独添加每个目录。 – DJMcMayhem