Import, use and compile a single c++ header file in an ios objective-c project
I'm sure the answer is simple but I am facing th开发者_Python百科e following problem ...
I want to use this c++ header file CAAudioUnitOutputCapturer.h (there is only a .h file) inside an ios objective-c xcode project.
Could someone tell me how to eliminate compilation errors and give me an example of how to use in Objective-C context?
Edit, i got this error :
CAAudioUnitOutputCapturer.h:64: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CAAudioUnitOutputCapturer'
At the moment, the compiler is trying to build your file as pure Objective C, which is causing these errors. Rename the file you are compiling it into as myFile.mm
(note the mm
extension). This will force the compiler to consider it as Objective C++ code, which by virtue of the header you're including, it is.
Any files that use the CAAudioUnitOutputCapturer classes must be Objective-C++ instead of Objective-C. You do that by using a .mm extension instead of .m.
In .mm files you can mix Objective-C classes and C++ classes.
Here is some information regarding Objective-C++.
The files in which you use the CAAudioUnitOutputCapturer.h
must either be Objective C++ files (default extension .mm
), or C++ files (extension .cpp
or .cc
). If you try to use them in an Objective C (extension .m
) file you'll get errors, as the compiler is expecting Objective C, not C++.
I do hope you have the object file or library file that contains the (compiled) code for the CAAudioUnitOutputCapturer
class, otherwise your .h
file is useless.
精彩评论