Compile cxx files in xcode - objective-c

I am new at IPHone development , I included a library with .cxx as implementation class and a .h header but still i get error at compiling , Please any help?
I get errors at lines like below
class StackEvent;

The Objective-C class that is including any C or C++ code must be renamed with a ".mm" suffix rather than ".m" in the implementation class.

Any Objective-C file (.m) that includes any header containing C++ code, either directly or by chained #includes, will likely fail with compile errors.
You need to rename all your .m files to .mm if they can "see" your C++ header.
If that causes too much renaming, then you'll have to limit your #includes, for example by take the C++ #include out of your header file and putting it only in the .mm files that need it.

Related

Are you supposed to use a separate header file with .mm files?

In Xcode if you are mixing c++ with objective c are you not supposed to use separate header file from the implementation? How do you declare c++ instance variables if it is supposed to be separate? You can't #include a c++ header file into a non .mm file or else you get compile errors.
Nevermind I figured out that you can extend the interface in the .mm file

Compile errors when when importing C++ headers (import loop) in Xcode

I know in order to avoid these type of compiling errors a way to solve this is to use #class MyClass in the header instead of import. Then #import the header in the implementation but this is not working for me.
The compile errors does not appear in the header file where I am importing the class but in the imported class' header.
The error I get is
class PVRShell --> Redefinition of 'PVRShell' as different kind of symbol.
Just in case I am using PowerVR and GLView(OpenGl) in my project.
Any ideas of how can I solve this compile error?
Rename your file extension from .m to .mm.
You have to do that if your class use Objective-C++.

Objective-C++ equivalent for the Objective-C function vm_deallocate

I have some Objective-C code that I'd like to convert to Objective-C++. To changed the extension of the source files from .m to .mm, and I set the filetype as Objective-C++ Source. However, now my project fails to build. Its giving an error on lines that I call vm_deallocate.
Here is the line:
vm_deallocate(mach_task_self(), (vm_address_t)prevInfo, prevInfo);
And the exact error is:
Use of undeclared identifier vm_deallocate
Is vm_deallocate restricted to Objective-C? Is there an equivalent Objective-C++ function?
No, since it's c.
This is more a header problem.
Make sure you have include in the right file
#include <mach/mach_init.h>
#include <mach/vm_map.h>
And it should compile without complain.

#include <new> not found, but only when the file is referenced from a specific header?

I reference the FBXSDK from a number of files, but one in particular causes this error to crop up. The particular header just imports the fbxsdk like so:
#import "fbxsdk.h"
I also reference it from the .mm file, and compiling with just the .mm referencing it works fine. It's only when I import in the header that the fbxsdk brings up errors like this:
include/fbxfilesdk/fbxfilesdk_memory.h:67:15: error: new: No such file or directory
and a bunch of expected '*' before '*' errors. I'm guessing it has to do with the compile order, or it's compiling the fbxsdk with a different rule set after reading the initial header? I'm still learning how to work with different compilers and libraries, so any suggestions or clues as to where to look for a solution would be helpful.
Working with Xcode, in a mix of Obj-C++ and C.
Chances are you are trying to import fbxsdk.h from a .m file, not a .mm file. If you're importing fbxsdk.h in one of your own .h files, you need to be sure that your own .h file is only imported by .mm files, not .m files.

How to use c++ template class in objective C

I want to use a Template class of C++ in my Objective C project.
I have read that it is supported.
When I try to import the template class that is written in C++ I get lot of errors like
Cannot find protocol declaration for 'class'
etc..
Can anyone give me a simple example of this.
Waiting for reply.
You are putting the objective c++ code in a .mm file? You need to use .mm files to tell the compiler its allows to parse c++ constructs in addition to objective-c and c.
You can't just change the name of a header file from .h to .mm - the name of the file containing the #include / #import directive needs to change.
// file: main.m
#import "cppclassdef.h" //will not work
#import "cppclassdef.mm" // also will not work. additionally will confuse XCode which will try to compile the .mm file by itself.
// file: main.mm
#import "cppclassdef.h" // this is how to do it.