1. Write c ++ classes:
C. h
# Include <stdio. h>
Class AA {
Public:
Void go ();
};
C. Mm
# Include "C. H"
AA: Go (){
Printf ("AA: Go ");
}
2. Compile the class just written. It can be divided into two runtime environments. One is to run the class in the simulator and the compilation target.CodeThe architecture is i386, one is to run in the real iPhone iPad, and the target code architecture is armv7. First, compile the code that can be run in the simulator. Use the GCC compiler of the simulator to open the command line, type the following command:
CD/Program/code/
/Developer/platforms/iphonesimulator. Platform/developer/usr/bin/llvm-G ++-4.2-arch i386-c-I././C. Mm
In this waySource codeDirectory will generate a c. o file, which is the target file we need. To compile the ARM architecture
/Developer/platforms/IOS. Platform/developer/usr/bin/llvm-G ++-4.2-arch i386-c-I././C. Mm
3. Open xcode and create an iOS app.ProgramClick the project name, select build phases, select link binary with librarys, expand the project, click the plus sign, and select the generated C. o. Compile and run the program. The calling code of objective-C is as follows. Note that the extension of the source code file of objective-C should be called. change m. mm to support the combination of objective-C and C ++:
-(Void) viewdidload {
[Super viewdidload];
AA * A = new AA ();
A-> go ();
Delete;
}
Note:
I tried again. Changing llvm-G ++-4.2 to G ++-4.2 can also be compiled successfully and run well, it can be referenced by the llvm-GCC (used by xcode) compiler after compilation by the GCC compiler.
/Developer/platforms/IOS. Platform/developer/usr/bin/g ++-4.2-arch i386-c-I././C. Mm