0

我的第一个问题是,如果我使用 opencv 库在 C++ 中编写一个类来检测图像中的任何对象并在 Objective-C(xcode 项目)中调用该 C++ 类,那么这种技术会起作用吗?

第二个问题是我如何在我的iphone 应用程序项目中添加c/c++类并在我的传统 ViewController 类中使用它。

到现在为止我所做的是 uder

:使用一个 ViewController 创建了一个 TabView 应用程序。:在该 ViewController 中添加了一个按钮。:添加了一个 File.c 类,它只是打印字符串。:在我的 ViewController.h 和 ViewController.m 类中导入“File.c”,例如

我的 ViewController.h 类

#import <UIkit/UIkit.h>
#import "file.c"

我的 ViewController.m 类

#import "FirstViewController.h"
#import "File.c"

现在按下按钮,我想调用我已经添加到项目中的那个 C 类。我希望得到好的和有益的答案。

问候

4

1 回答 1

0

文件.c

#ifndef testC_File_c
#define testC_File_c
#include <stdio.h>
void say_hello() {
    printf("Hello World!");
}
#endif

视图控制器.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction) buttonDown:(id)sender;
@end

视图控制器.mm

#import "ViewController.h"
#include "File.c"
@interface ViewController ()

@end

@implementation ViewController

- (IBAction) buttonDown:(id)sender
{
    say_hello();
}
- (void)viewDidLoad
{
    [super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
于 2012-09-28T05:39:09.973 回答