2011-10-24 79 views
2

我正试图获得的升压的例子之一,从该网站的工作:Boost示例不能在VS2010上编译?

http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/example/http/client/async_client.cpp

但每当我建立并试图执行,我一直得到从VS2010如下:

1>------ Build started: Project: highfreqdemo, Configuration: Debug Win32 ------ 
1>Build started 24/10/2011 18:41:08. 
1>InitializeBuildStatus: 
1> Touching "Debug\highfreqdemo.unsuccessfulbuild". 
1>ClCompile: 
1> All outputs are up-to-date. 
1> highfreqdemo.cpp 
1>c:\users\x\documents\visual studio 2010\projects\highfreqdemo\highfreqdemo\highfreqdemo.cpp(4): warning C4627: '#include <iostream>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>c:\users\x\documents\visual studio 2010\projects\highfreqdemo\highfreqdemo\highfreqdemo.cpp(5): warning C4627: '#include <istream>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>c:\users\x\documents\visual studio 2010\projects\highfreqdemo\highfreqdemo\highfreqdemo.cpp(6): warning C4627: '#include <ostream>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>c:\users\x\documents\visual studio 2010\projects\highfreqdemo\highfreqdemo\highfreqdemo.cpp(7): warning C4627: '#include <string>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>c:\users\x\documents\visual studio 2010\projects\highfreqdemo\highfreqdemo\highfreqdemo.cpp(8): warning C4627: '#include <boost/asio.hpp>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>c:\users\x\documents\visual studio 2010\projects\highfreqdemo\highfreqdemo\highfreqdemo.cpp(9): warning C4627: '#include <boost/bind.hpp>': skipped when looking for precompiled header use 
1>   Add directive to 'StdAfx.h' or rebuild precompiled header 
1>c:\users\x\documents\visual studio 2010\projects\highfreqdemo\highfreqdemo\highfreqdemo.cpp(199): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source? 
1> 
1>Build FAILED. 
1> 
1>Time Elapsed 00:00:00.76 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

我有点不确定究竟该怎么做才能解决这个问题?

回答

5
Add directive to 'StdAfx.h' or rebuild precompiled header 

您的项目配置了预编译头支持,但是你有没有包含在源文件的预编译的头。

需要将预编译头文件(在本例中为StdAfx.h)包含在每个配置为使用预编译头的源文件的顶部。 (在C/C++ - >预编译头文件中,将预编译头文件属性设置为“不使用预编译头文件”;也可以为单个源文件设置此属性)。

+0

你会在这里推荐什么?不使用预编译头文件的缺点是什么?我不完全确定我了解后果 – user997112

+0

预编译头文件用于提高编译性能。如果你有一个小项目,你不需要它们。最好的选择是从空白项目模板创建一个新项目,该模板不包含默认的预编译头,并从那里开始。 –

1

警告和错误非常明显;在包含标准和Boost标头之前,您需要将#include "StdAfx.h"添加到highfreqdemo.cpp文件中。

+0

我不明白错误的原因是因为我认为这个例子可以'开箱即用' – user997112