Use a C++ file in Cocoa iPhone App

Use a C++ file in Cocoa iPhone App

I'm trying to use the functionality of the example iPhone app AQOfflineRenderTest in my app (this app specifically isn't important, I just thought it worth mentioning). I have a C++ file with method called:

    void DoAQOfflineRender(CFURLRef sourceURL, CFURLRef destinationURL) 

I'm trying to call this from my Cocoa Objective-C class. The example app I referenced above does this by declaring the method in the header file like so:

    - (IBAction)doSomethingAction:(id)sender;     @end     void DoAQOfflineRender(CFURLRef sourceURL, CFURLRef destinationURL); 

In the implementation file I call the doSomethingAction which calls renderAudio and executes the same code:

    DoAQOfflineRender(sourceURL, destinationURL); 

When I execute I get the error: _DoAQOfflineRender", referenced from: -[myViewController renderAudio] in myViewController.o symbol(s) not found collect2: ld returned 1 exit status

Am I missing a reference to this C++ class? It doesn't specify one in the example app but it runs.

Please help and thanks!


Converting OpenGL Primitives to OpenGLES


What you're missing is the implementation of DoAQOfflineRender -- did you forget to link in the library where this routine is defined?.
casting a NSString to char problem

Trying to include iPhone OpenGLES headers in C++ code

Is NSTimer auto retained?


Submit ajax form on keyboard close without a submit button on the iphone?
It looks like you're using .m as the extension for you Objective-C source file so the compiler thinks you are referencing a C function.

Why does this create a memory leak (iPhone)?
Try changing the extension to .mm..
UICachedDeviceWhiteColor and NSAutoRelease for table cell mem leaks


To call a C++ function from a C or Objective-C file, you must declare it with extern "C" linkage in C++..
#if __cplusplus extern "C" { #endif  void DoAQOfflineRender(CFURLRef sourceURL, CFURLRef destinationURL);  #if __cplusplus } #endif 
The reason for this is that C++ functions’ names are modified by encoding their types, so that functions with the same name but different signatures become different symbols.

For example, DoAQOfflineRender(CFURLRef, CFURLRef) becomes __Z17DoAQOfflineRenderPK7__CFURLS1_ without extern "C", but _DoAQOfflineRender with it, which is what the C/Objective-C expects..

74 out of 100 based on 59 user ratings 1084 reviews