Tutorial :iphone error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 'foo'



Question:

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.

What does error: expected '=', ',', ';', 'asm' or '__attribute__' before 'foo' mean?... I get this error multiple times for different files

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)

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.zip and the original is here SpeakHere.zip


Solution:1

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.

Rename it to SpeakHerePortAppDelegate.mm (double m) so that it is compiled as Objective C++ and your problem is resolved.

Name all your files .mm and then all your code will be compiled as Objective C++


Solution:2

In my case, the .h and .m in question are built fine with regular target, and the App can run as well.

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.,

  • extern double const kTimeout; // fine
  • extern 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"


Solution:3

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.


Solution:4

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.

@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.


Solution:5

It means that you have a syntax error. If you paste the code in question, it's easier to debug.


Solution:6

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.

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.objcpp for the objective-c class that was calling my C++ class.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »