如何使用Cocos3D静态库中的Objective-C实用方法(CC3Foundation.m);“mm”;文件(Objective-C+;+;)?

如何使用Cocos3D静态库中的Objective-C实用方法(CC3Foundation.m);“mm”;文件(Objective-C+;+;)?,objective-c,objective-c++,bulletphysics,cocos3d,Objective C,Objective C++,Bulletphysics,Cocos3d,我正在构建一个Cocos3D应用程序,它使用 iOS中的COCO3D(Objective-C静态库)和子弹物理(C++静态库) P>我的代码文件大部分是“.mm”文件(ObjuleC++),在目标构建选项中使用Objto-C方法和C++函数,在目标构建选项中使用“-Objc+LSTDc++”链接标志。 问题是:在“mm”文件中,从Cocos3D静态库中的“CC3Foundation.m”调用实用程序方法会导致链接错误(“未定义符号”)。在Cocos3D中调用其他Cocos3D的类方法没有任何问

我正在构建一个Cocos3D应用程序,它使用 iOS中的COCO3D(Objective-C静态库)和子弹物理(C++静态库)

<> P>我的代码文件大部分是“.mm”文件(ObjuleC++),在目标构建选项中使用Objto-C方法和C++函数,在目标构建选项中使用“-Objc+LSTDc++”链接标志。 问题是:在“mm”文件中,从Cocos3D静态库中的“CC3Foundation.m”调用实用程序方法会导致链接错误(“未定义符号”)。在Cocos3D中调用其他Cocos3D的类方法没有任何问题

Cocos3D中的“CC3Foundation.m”是其他Objective-C类可以使用的实用方法(不是类成员方法)文件。它没有任何类声明/实现

// TestClass.h ("h" header file)
@interface TestClass
...
-(void) testMethod;
...
@end

// TestClass.mm ("mm" file)
#import "CC3Foundation.h"
@implementation TestClass
...
-(void) testMethod{
  CC3Vector va[2];
  
  // "NSStringFromCC3Vectors()" from "CC3Foundation.m" in Cocos3D static library.
  // Undefined symbol: NSStringFromCC3Vectors(CC3Vector*, unsigned int)
  NSLog(@"va: %@", NSStringFromCC3Vectors(va,2)); // link error

}
...
@end



// from cocos3D static library

// CC3Foundation.h
NSString* NSStringFromCC3Vectors(CC3Vector* vectors, GLuint vectorCount);

// CC3Foundation.m
NSString* NSStringFromCC3Vectors(CC3Vector* vectors, GLuint vectorCount) {
    NSMutableString* desc = [NSMutableString stringWithCapacity: (vectorCount * 8)];
    for (GLuint vIdx = 0; vIdx < vectorCount; vIdx++)
        [desc appendFormat: @"\n\t%@", NSStringFromCC3Vector(vectors[vIdx])];
    return desc;
}

Cocos3D中的Objective-C++文件之一,“CC3VertexArraysPODExtensions.mm”使用“CC3Foundation.h/m”,并以相同的方式导入“CC3Foundation.h”

关于外部“C”的有用帖子


Cocos看起来很不错,但我从未真正使用过它,但根据您的描述,我认为您需要确保
CC3Foundation.m
是您目标的一部分。
// TestClass.mm ("mm" file)

// Use extern "C" linkage to let compiler/linker know "CCFoundation.h/m" is "C" function files.
// Must import "CC3Foundation.h" first 
// because "CC3Foundation" is also imported in other classes 
// and those classes are also imported in this mm file.
extern "C" {
#import "CC3Foundation.h"
}

@implementation TestClass
...
-(void) testMethod{
  CC3Vector va[2];

  // "NSStringFromCC3Vectors()" from "CC3Foundation.m" in Cocos3D static library.
  NSLog(@"va: %@", NSStringFromCC3Vectors(va,2)); // no linker error

}
...
@end