2011-10-24 114 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