2013-04-23 86 views
3
extern "C" 
{ 
#endif 
#include <stdint.h> 
#include <limits.h> 
#include "attributes.h" 
} 
#endif 

我加extern "C" { } 然後我得到了C2059 string錯誤 所以我試圖用#endif,現在我還有一個4個錯誤。C2059語法錯誤'string'?

Error 1 error C2059: syntax error : 'string' d:\c-sharp\c++ 
compiling\consoleapplication7\consoleapplication7\libavutil\rational.h 31 1 
ConsoleApplication7 

我該如何解決這個字符串錯誤?

+0

爲什麼你首先做這個? – 2013-04-23 12:37:34

+5

'#ifdef X ... #endif'通常是怎麼回事,而不是'#endif'兩次。除非你還沒有發佈你的所有代碼? – 2013-04-23 12:37:36

+4

'extern「C」{'聲明和關閉'}'通常會被'#ifdef __cplusplus','#endif'包圍。如果你不這樣做,你必須確保你的頭文件不包含在C源代碼文件中 – simonc 2013-04-23 12:38:35

回答

15

有人猜測,你是否包含來自C源文件的這段代碼?

extern "C" {警衛只有C++需要(或理解)。您可以從C文件中忽略它們,應該將它們包含在C++文件中,並且應該在頭文件中使用__cplusplus ifdef來保護它們。

#ifdef __cplusplus 
extern "C" { 
#endif 
#include <stdint.h> 
#include <limits.h> 
#include "attributes.h" 
#ifdef __cplusplus 
} 
#endif 
+2

您通常不會將頭文件放在'extern「C」{}'部分中。 – 2013-04-23 13:01:53

相關問題