4

I've made a template app where I've grabbed the recording part of the SpeakHere example and removed the file handling part, but I'm struggeling to get the C++ part of the app working right. As soon as it enters the C++ class, it gets syntax errors. If I don't import the header files from C++ (and then of course don't use the code) into my Objective C classes, all works fine. I cannot see the difference between how I'm doing it and the example is doing it. Can you see the difference?

I've posted the entire code here: http://github.com/niklassaers/testFFT

The build errors I get are:

testFFT/CAStreamBasicDescription.h:91:0 testFFT/CAStreamBasicDescription.h:91: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CAStreamBasicDescription'
testFFT/CAStreamBasicDescription.h:298:0 testFFT/CAStreamBasicDescription.h:298: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
testFFT/CAStreamBasicDescription.h:299:0 testFFT/CAStreamBasicDescription.h:299: error: expected '=', ',', ';', 'asm' or '__attribute__' before '==' token
testFFT/CAStreamBasicDescription.h:301:0 testFFT/CAStreamBasicDescription.h:301: error: expected '=', ',', ';', 'asm' or '__attribute__' before '!=' token
testFFT/CAStreamBasicDescription.h:302:0 testFFT/CAStreamBasicDescription.h:302: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<=' token
testFFT/CAStreamBasicDescription.h:303:0 testFFT/CAStreamBasicDescription.h:303: error: expected '=', ',', ';', 'asm' or '__attribute__' before '>=' token
testFFT/CAStreamBasicDescription.h:304:0 testFFT/CAStreamBasicDescription.h:304: error: expected '=', ',', ';', 'asm' or '__attribute__' before '>' token
testFFT/CAStreamBasicDescription.h:307:0 testFFT/CAStreamBasicDescription.h:307: error: expected ';', ',' or ')' before '&' token
testFFT/CAXException.h:65:0 testFFT/CAXException.h:65: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CAX4CCString'
testFFT/CAXException.h:87:0 testFFT/CAXException.h:87: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CAXException'
testFFT/AQRecorder.h:59:0 testFFT/AQRecorder.h:59: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'AQRecorder'
testFFT/RecorderLink.h:57:0 testFFT/RecorderLink.h:57: error: expected specifier-qualifier-list before 'AQRecorder'
testFFT/RecorderLink.h:62:0 testFFT/RecorderLink.h:62: error: expected specifier-qualifier-list before 'AQRecorder'

Any idea what's going on here?

Cheers

Nik

niklassaers
  • 8,480
  • 20
  • 99
  • 146

1 Answers1

5

You are indirectly including the C++ headers into plain Objective-C code (.m) - that won't work, you have to use Objective-C++ (.mm) all the way or encapsulate the C++ classes in Objective-C classes using opaque pointers.

One problematic chain:

  • Classes/MainViewController.m, plain Objective-C, includes
  • RecorderLink.h, includes
  • AQRecorder.h, which is C++
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • So would it be your recommendation to rename MainViewController.m to MainViewController.mm ? – niklassaers Apr 29 '10 at 17:23
  • @niklassaers: Going with the chain above, i'd personally try to keep the already good seperation of C++ and Objective-C (application core and GUI layer) - in this example you only have to get the C++ include and the C++ pointer type out of `RecorderLink.h`. See here for one possible approach: http://stackoverflow.com/questions/2262011/adding-c-object-to-objective-c-class/2262395#2262395 – Georg Fritzsche Apr 29 '10 at 17:31
  • Voila, an implementation using opaque pointers has been pushed to github – niklassaers Apr 29 '10 at 18:11
  • PS, I still don't get how the SpeakHere example got around this problem, though – niklassaers Apr 29 '10 at 18:14
  • @niklassaers: Is that original one viewable online? – Georg Fritzsche Apr 29 '10 at 18:19
  • Yes, it's here: http://developer.apple.com/iphone/library/samplecode/SpeakHere/Introduction/Intro.html – niklassaers Apr 30 '10 at 15:10
  • @niklassaers: From a quick glance through it, the plain Objective-C sources (`.m`) in that project simply don't include any C++ headers. E.g. in `SpeakHereViewController.h` they only forward declare `@class SpeakHereController`, instead of including its header which contains C++ includes. – Georg Fritzsche May 01 '10 at 05:17