tags:

views:

916

answers:

2

I am trying to reuse Apple's Speak Here sample code in my own iPhone app. I downloaded and compiled the project with no problems, so I then added some of the files to my own application. When I try to compile my own application, the compiler gives me

MeterTable.h:54: error: syntax error before 'MeterTable'

The relevant code is:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

class MeterTable  // line 54
{
public:

It looks kind of like xcode isn't recognizing MeterTable.h and MeterTable.mm as C++ files. I've checked File>>GetInfo for MeterTable.mm, though, and it lists filetype as sourcecode.cpp.cpp.

Why won't this compile?

A: 

Try to enclose #include directives with extern "C" { }

mouviciel
+1  A: 
  1. You're including "MeterTable.h" in a non C++ file other than MasterTable.mm.
  2. The error is not in 'MeterTable.h' but in the header included before it. Note that <stdlib.h>... can be a noop if they are included before.

If you want to make sure your file is compiled with C++, you can add this code to the begining of MasterTable.mm:

#ifdef __cplusplus
#error "compiled as C++"
#else
#error "compiled as C"
#endif
mfazekas
Thanks! You're right, I was including MeterTable.h in a non-C++ file. Interestingly, I dropped in your code and I still got the "compiled as C++ error" though. Not sure what's going on there.Anyway, I'm back on track, so thanks very much!
niels
Again the headerfile will be included in both C++ and non C++ context.If you change #error to #warning you should see both
mfazekas