找不到体系结构i386的目标C和C++符号

Objective C and C++ symbol(s) not found for architecture i386

本文关键字:C++ 符号 目标 体系结构 i386 找不到      更新时间:2023-10-16

我有Objective-C函数和C++文件,我将其重命名为.mm并连接到我的项目,我需要在C++文件中使用Objective-C功能,但Xcode给了我:

体系结构i386的未定义符号:"maxRadiusFinder(double*,int,int)",引用自:RALG.o 中的Fun(int,double,double*,double*int,double[2],int,int)

我的代码Objective-C代码:

 double maxRadiusFinder(double* algoPoints1,int count,int numberC)
{
NSMutableArray* algoPoints=[[NSMutableArray alloc] init];
for (int i=0; i<count; i++) {
    Points *temp=[[Points alloc] init];
    [temp setXCor:algoPoints1[i]];
    [temp setYCor:algoPoints1[i+count]];
    [algoPoints addObject:temp];
}
int howMany = (kDefaultGraphWidth - kOffsetX) / kStepX;
int howManyHorizontal = (kGraphBottom - kGraphTop - kOffsetY) / kStepY;
NSMutableArray *distancesKCover=[[NSMutableArray alloc]init];
for (NSUInteger j=0; j<=howManyHorizontal; j++) {
    for (NSUInteger i=0; i<=howMany; i++) {
        Points *temp=[[Points alloc] init];
        [temp setXCor:i*kStepX];
        [temp setYCor:j*kStepY];
        NSMutableArray *distances=[[NSMutableArray alloc]init];
        for(NSUInteger i1=0;i<[algoPoints count];i++)
        {
            float temp1=MAX(fabsf([[algoPoints objectAtIndex:i1] xCor]-[temp xCor]),fabsf([[algoPoints objectAtIndex:i1] yCor]-[temp yCor]));
            [distances addObject:[NSNumber numberWithFloat:temp1]];
        }
        NSArray *sortedDistances=[distances sortedArrayUsingSelector:@selector(compare:)];
        [distancesKCover addObject:[sortedDistances objectAtIndex:numberC]];
    }
}
double max = [[distancesKCover valueForKeyPath:@"@max.doubleValue"] doubleValue];
return max;
 }

并且该函数在.mm文件中的c++调用:

  rd += maxRadiusFinder(g, 10, 10);

objective-c具有"c"链接。Objective-c++具有c++链接。C和C++是不同的语言,它们有一些共同的语法。

您需要在.mm上下文中将函数声明为extern"C"

例如

声明.h:

#ifdef __cplusplus
extern "C" {
#endif
// all function declarations here are common to C and C++. They will all have C linkage
// i.e. no name mangling and no overloading
double maxRadiusFinder(double* algoPoints1,int count,int numberC);
#ifdef __cplusplus
}
#endif