我希望从一个C++文件调用Objective C函数。当我在C++文件(Algebra.cpp)中包含Objective C文件(UnZip.h)的头文件时,构建失败了。我该怎么办?如果我在Algebra.cpp中删除对Math.h的任何引用,一切都可以正常构建。但我不能将Algebra.cpp的名称更改为Algebra.mm,因为它在其他多个地方被使用。
文件Math.h
文件Math.h
void MathFormula(const char *sourceData, const char *answer);
文件 Math.m
#import <Foundation/Foundation.h>
#import "MathDocument.h"
void MathFormula(const char *sourceFile, const char *answer)
{
NSString * sFile = [NSString stringWithUTF8String:sourceFile];
NSString * ans = [NSString stringWithUTF8String:answer];
MathDocument * mathDocument = [[MathDocument alloc] initWithPath:sFile];
[mathDocument runFormula:ans];
}
Algebra.cpp
#include ...
#include Math.h
{
---
const char * sourceFile = "/Users/u1/pckg.zip";
const char * destPath = "/Users/u1";
MathFormula(sourceFile, destPath);
---
}