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

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.