[英]How to Call a C++ Method in Objective-C
I have C++ files: C.cpp and Ch 我有C ++文件:C.cpp和Ch
//C.h
#ifndef __ThreeMoreOpenCV__SourceC__
#define __ThreeMoreOpenCV__SourceC__
#include <iostream>
class C
{
public:
static void Cmethod ();
};
#endif
//C.cpp
#include "SourceC.h"
using namespace std;
void Cmethod()
{
printf("ff");
}
Also I have Wrapper.h/.mm 我也有Wrapper.h / .mm
//Wrapper.h
#import <Foundation/Foundation.h>
@interface CVWrapper : NSObject
+(void)returnCmethod;
@end
//Wrapper.mm
#import "Wrapper.h"
#import "C.h"
@implementation CVWrapper
+(void)returnCmethod
{
C::Cmethod();
}
@end
I have no idea but i'm getting an error like: 我不知道,但出现类似以下错误:
"C::Cmethod()", referenced from: +[Wrapper returnCmethod] in Wrapper.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation). 从以下位置引用“ C :: Cmethod()”:Wrapper.o中的+ [Wrapper returnCmethod] ld:体系结构i386铛未找到符号:错误:链接器命令失败,退出代码为1(使用-v查看调用)。
Can anybody tell me what is correct way to call function? 谁能告诉我调用函数的正确方法是什么?
You haven't actually implemented the Cmethod function in your C class. 您实际上尚未在C类中实现Cmethod函数。 You need to implement it with
C::
in the function header, like: 您需要在函数头中使用
C::
来实现它,例如:
void C::Cmethod()
{
printf("ff");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.