How to compile c++ in xCode for your IPhone app?
I am doing my first steps in IPhone developing. I want to use some c\c++ code but I can't find any refere开发者_C百科nce of how it's done (will very appriciate if you can also refer me to your source when you give an answear)
I have a file called calc.h containing a "calculator" class with simple add and mult functions, I imported it exactly as I did with an Objective-C header file. What am I suppose to do now?
Whatever you were doing when you were coding just in C/C++.
For example:
#include "calc.h"
....
-(void) testCode { //obj-c
float x = 3;
float y = 8.0;
float sumOfTwo = sum(x, y);
}
Assuming that you have a function named sum in your header file similar with the one used above.
If you use standard extensions for the source files (e.g. .cpp
/ .c
) you can simply build them without doing anything special.
If you use uncommon extensions you need to set the file type manually: In File → Get Info set File Type to sourcecode.cpp.cpp / sourcecode.c.c.
Note however that you can't use C++ in plain Objective-C (.m
) files - if you want to do that you need to use Objective-C++ (.mm
) instead.
For using C there is no such restriction as Objective-C is a superset of C - as with C++ you may need to watch out for uses of identifiers that are keywords in Objective-C though.
精彩评论