I now have to porting C++ code to iOS, trying to build static library by original C++ code and load the library on iOS. Because the original code is heavy, I start a small test to verify my steps could work or not.
First I need to build library (.a), which prints some string. I compile the following code and generate a library(.a) file
//talk.h
...
#include <iostream>
class Talk {
Talk();
void printHello();
void printWord(char*);
};
//talk.cpp
#include "talk.h"
using namespace std;
void Talk::printHello() {
cout << "Hello World";
}
void Talk::printWord(char* word) {
cout << "Hello" << word;
}
The second step I try to do is open a new project for iOS app and then set link to the library file, also include corresponding "talk.h" header file. However, some errors happen on the header file even though I build library successfully.
The errors indicate that
I have try to rename controller.m to controller.mm, but it not fixes the problem
How to import the header file written in C++ for using library on iOS? Thanks
A rough outline:
In Xcode (starting with an either one of the template iOS Application projects (or an existing one):
Xcode will have taken care of setting everything else up for you, including compiler flags and header search paths.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With