【问题标题】:C2059 syntax error 'string' ?C2059 语法错误“字符串”?
【发布时间】:2021-04-07 06:48:32
【问题描述】:
extern "C" 
{
#endif
#include <stdint.h>
#include <limits.h>
#include "attributes.h"
}
#endif

我添加了extern "C" { } 然后我得到了C2059 string 错误 所以我尝试使用#endif,现在又出现了4个错误。

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

我该如何解决这个字符串错误?

【问题讨论】:

  • 你为什么要这样做?
  • #ifdef X ... #endif 通常是这样,而不是 #endif 两次。除非你还没有发布你所有的代码?
  • extern "C" { 声明和关闭} 通常由#ifdef __cplusplus、#endif 括起来。如果您不这样做,则必须确保您的标头未包含在 C 源文件中
  • 请尽可能完整地发布原始代码(另请参阅sscce.org 寻求帮助)。然后请发布完整且未经编辑的错误消息,同时指出它们在源代码中的哪一行。
  • Joachim 原帖我的代码问题在这里:stackoverflow.com/questions/16155783/… 我有 9 错误的这个链接。我尝试谷歌并尝试任何解决方案将所有 bin 文件和 dll 文件复制到调试和解决方案目录,但没有任何帮助。所以我尝试了这个外部“C”,但它也没有帮助。无法弄清楚为什么会发生此错误。

标签: c++ c


【解决方案1】:

猜测一下,您是否包含来自 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

【讨论】:

  • 您通常不会将标题放在extern "C" { } 部分中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-02
  • 1970-01-01
  • 2016-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多