objective-c iphone 错误:在 ''foo' 之前应为 '=', ',', ';', 'asm' 或 '__attribute__'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/990906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iphone error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 'foo'
提问by dizy
I'm trying to port the speakhere example into another app and I'm having issues. I copied all the files, and all the frameworks, but for some reason I get a bunch of compile errors that I've never seen before and thus don't know what to do. The only difference is that i'm not suing IB and so i had to change it slightly.
我正在尝试将 speakhere 示例移植到另一个应用程序中,但遇到了问题。我复制了所有文件和所有框架,但由于某种原因,我收到了一堆我以前从未见过的编译错误,因此不知道该怎么做。唯一的区别是我没有起诉IB,所以我不得不稍微改变一下。
What does error: expected '=', ',', ';', 'asm' or '__attribute__' before 'foo'mean?... I get this error multiple times for different files
什么 error: expected '=', ',', ';', 'asm' or '__attribute__' before 'foo'意思?...对于不同的文件,我多次收到此错误
In my situation the first error is pointing at 'MeterTable'.. a class that includes <stdlib.h>,<stdio.h>and <math.h>. But those files seem to be importing fine (if i remove them i get more errors)
在我的情况下,第一个错误指向 'MeterTable'.. 一个包含<stdlib.h>,<stdio.h>和的类<math.h>。但是这些文件似乎可以正常导入(如果我删除它们,我会收到更多错误)
Any suggestions on how to debug this?
关于如何调试这个的任何建议?
TIA!
蒂亚!
EDIT: I still can't seem to figure it out. I'm literally just copying files from the example into another project. Can someone check it out please ? SpeakHerePort.zipand the original is here SpeakHere.zip
编辑:我似乎仍然无法弄清楚。我实际上只是将示例中的文件复制到另一个项目中。有人可以检查一下吗? SpeakHerePort.zip和原文在这里SpeakHere.zip
回答by Peter N Lewis
Your problem is that you are compiling SpeakHerePortAppDelegate.m, which is an Objective C file, but it is indirectly including MeterTable.h which is a C++ header file.
您的问题是您正在编译 SpeakHerePortAppDelegate.m,它是一个 Objective C 文件,但它间接包含了 MeterTable.h,它是一个 C++ 头文件。
Rename it to SpeakHerePortAppDelegate.mm (double m) so that it is compiled as Objective C++ and your problem is resolved.
将其重命名为 SpeakHerePortAppDelegate.mm(双 m),以便将其编译为 Objective C++ 并解决您的问题。
Name all your files .mm and then all your code will be compiled as Objective C++
将所有文件命名为 .mm,然后将所有代码编译为 Objective C++
回答by HaiMing
In my case, the .h and .m in question are built fine with regular target, and the App can run as well.
就我而言,有问题的 .h 和 .m 使用常规目标构建得很好,并且应用程序也可以运行。
However after the subset of the files are moved under a static library target, it gets this compile error when the static library is built.
但是,在将文件子集移动到静态库目标下后,构建静态库时会出现此编译错误。
Was stuck for a while & tried the above mentioned techniques, unfortunately they didn't help in my case.
卡住了一段时间并尝试了上述技术,不幸的是,它们对我的情况没有帮助。
Noted that this error happened only for the NSString*, for e.g.,
注意这个错误只发生在 NSString* 上,例如,
extern double const kTimeout; // fineextern NSString* const kImageType; // compile error
extern double const kTimeout; // fineextern NSString* const kImageType; // compile error
After the above analysis & little break, eventually the problem is resolved by adding the the following import to the .h - "Foundation/Foundation.h"
经过上述分析和稍作休息,最终通过将以下导入添加到 .h 中解决了问题 - "Foundation/Foundation.h"
回答by Quinn Taylor
It sounds like an unfinished declaration, probably in a header file. Search for 'foo' (or whatever the symbol actually is) across all project files, using ??F (Edit ? Find ? Find In Project...) in Xcode, and/or examine the headers you're including where MeterTable is declared. Sometimes the compiler gets confused about the actual location of the error, since header files are frequently #imported into other files, so the problem can be manifest in multiple locations.
这听起来像是一个未完成的声明,可能在头文件中。在所有项目文件中搜索“foo”(或任何实际的符号),在 Xcode 中使用 ??F(编辑?查找?在项目中查找...),和/或检查包含 MeterTable 所在位置的标题宣布。有时编译器对错误的实际位置感到困惑,因为头文件经常#imported 到其他文件中,所以问题可能在多个位置出现。
回答by Matt
This might not have applied to this exact situation, but I had this exact error too, which was caused by a bad forward declaration. In Objective-C, make sure your forward-declares begin with the @ sign - e.g.
这可能不适用于这种确切的情况,但我也有这个确切的错误,这是由错误的前向声明引起的。在 Objective-C 中,确保您的前向声明以 @ 符号开头 - 例如
@class MyClass;
Those of us still on autopilot from C++ will forget the @, see that XCode has highlighted class as a reserved keyword, and think all is well with the world. It is not.
我们这些仍然使用 C++ 自动驾驶的人会忘记 @,看到 XCode 将 class 突出显示为保留关键字,并认为世界上一切都很好。它不是。
回答by oddmeter
I had a similar scenario to some of the posts above. I'd written a C++ class based off of the examples in the Audio Queue Services documentation, and had this compilation issue in a test project. This post helped a tremendous amount.
我对上面的一些帖子有类似的情况。我根据音频队列服务文档中的示例编写了一个 C++ 类,并在测试项目中遇到了这个编译问题。这篇文章帮助了很多。
Today, I'm incorporating the C++ class in my project, and got the build error again. In my scenario, I had to also set the type (using the "Get Info" window) to sourcecode.cpp.objcppfor the objective-c class that was calling my C++ class.
今天,我将 C++ 类合并到我的项目中,但再次出现构建错误。在我的场景中,我还必须为调用我的 C++ 类的 Objective-c 类设置类型(使用“获取信息”窗口)到sourcecode.cpp.objcpp。
回答by Eric
It means that you have a syntax error. If you paste the code in question, it's easier to debug.
这意味着您有语法错误。如果您粘贴有问题的代码,则更容易调试。

