2012-04-23 45 views
4

我尝试使用boost python和 visual C++ 2008 express构建简单的hello world。错误C2653:'boost':不是类或名称空间名称VC++ 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(); 
    } 
} 
+0

尝试移动'的#include <升压/ python.hpp>'*后*'#包括 “stdafx.h中”'。 – 2012-04-23 13:35:22

+0

谢谢,这解决了它。你可以将它发布为答案。 – user891908 2012-04-23 13:49:12

+0

当然。完成... – 2012-04-23 14:04:01

回答

3

由于微软的预编译头是如何工作的一些怪事,你总是希望:

#include "stdafx.h" 

...因为在你使用它的任何文件首创线。标题的任何其他需要后前来这一点,所以你想要的:

#include "stdafx.h" 
#include <boost/python.h> 
相关问题