找不到体系结构i386的目标C和C++符号
Objective C and C++ symbol(s) not found for architecture i386
我有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
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 将无符号char*转换为std::istream*C++
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- vscode g++链路故障:体系结构x86_64的未定义符号
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 使用gcc从静态链接的文件中查找可选符号
- C++中无符号字符溢出
- 使用无符号字符数组有效存储内存
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- VC++本机单元测试,找不到调试符号
- 为什么我必须在C++中添加一个赋值符号来声明一个数组
- 检查TCHAR数组输入是否为带符号整数C++
- 用符号版本替换对函数的所有调用
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何打印boost多精度128位无符号整数
- C++模板函数,用于比较任何无符号整数和有符号整数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号