开发者

Apple Mach-O Linker (Id) Error : While calling c++ file from .m file

I have some cpp file where my functions are written. I want to call that functions in my iPhone app? How can i call c++ methods in my .m file???

Here is my .cpp file

int add(int a, int b)
{
    return a+b;
}

Now in my viewDidLoad event i am using following code just to fetch the result and display in a开发者_运维百科 Label.

NSNumber *n = [[NSNumber alloc] initWithInt:add(5,7)];
[myLabel setText:[NSString stringWithFormat:@"%@",n]];

I received the following Error while compiling:

Undefined symbols for architecture i386:
  "_add", referenced from:
      -[usingc__ViewController viewDidLoad] in usingc__ViewController.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

Where is the error in the code?? What edit is necessary for this??


If you want to use C++ file in your Objective-C file, change the file extension from .m to .mm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜