错误C2653:'boost':不是VC ++ 2008 express的类或命名空间名称

时间:2012-04-23 13:32:51

标签: visual-c++ boost-python

我尝试用boost python构建简单的hello世界 visual c ++ 2008 express。


我在

中包含了路径E:\Program Files\boost\boost_1_47\

|Tools|Options|VC++ Directories|包含文件(并试图将相同的路径放到所有其他文件中),

但我仍然得到错误
'boost' : is not a class or namespace name

源代码是:

#include <boost/python.hpp>
#include "stdafx.h"

using namespace boost::python;

int main( int argc, char ** argv ) {
  try {
    Py_Initialize();

    object main_module((
      handle<>(borrowed(PyImport_AddModule("__main__")))));

    object main_namespace = main_module.attr("__dict__");

    handle<> ignored(( PyRun_String( "print \"Hello, World\"",
                                     Py_file_input,
                                     main_namespace.ptr(),
                                     main_namespace.ptr() ) ));
  } catch( error_already_set ) {
    PyErr_Print();
  }
}

1 个答案:

答案 0 :(得分:3)

由于微软预编译头的工作方式有些奇怪,你总是想要:

#include "stdafx.h" 

...在您使用它的任何文件中作为第一个行。任何其他标题需要之后,所以你想要:

#include "stdafx.h"
#include <boost/python.h>