如何将Chipmunk库包含到iPhone Xcode项目中?
问题描述:
[求助]如何将Chipmunk库包含到iPhone Xcode项目中?
我从cocos2d +花栗鼠模板复制花栗鼠文件夹结构,并构建好。
- 类/花栗鼠/包括 'SRC' 文件夹
- 类/花栗鼠/只花栗鼠 '包括' 文件夹
感谢贝塔试图帮助/ src目录。
:::::
我下载花栗鼠5.3.1和一个简单的例子尝试,但我收到此错误编译:关于正确添加花栗鼠库
Undefined symbols:
"_cpSpaceStep", referenced from:
-[ChipmunkTestViewController delta:] in ChipmunkTestViewController.o
"_cpBodyNew", referenced from:
-[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
"_cpSpaceAddShape", referenced from:
-[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
"_cpSpaceAddBody", referenced from:
-[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
"_cpSpaceHashEach", referenced from:
-[ChipmunkTestViewController delta:] in ChipmunkTestViewController.o
"_cpInitChipmunk", referenced from:
-[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
"_cpCircleShapeNew", referenced from:
-[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
"_cpSpaceNew", referenced from:
-[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
我不知道,我必须包括来自花栗鼠.tgz的什么消息?
下面的代码:
ChipmunkTestViewController.h
#import <UIKit/UIKit.h>
#import "chipmunk.h"
@interface ChipmunkTestViewController : UIViewController {
UIImageView *barra;
UIImageView *esfera;
cpSpace *space;
}
- (void) configurarChipmunk;
- (void) delta:(NSTimer *)timer;
void updateShape(void *ptr, void *unused);
@end
ChipmunkTestViewController.m
#import "ChipmunkTestViewController.h"
@implementation ChipmunkTestViewController
- (void) configurarChipmunk {
cpInitChipmunk(); // Init Chipmunk engine
space = cpSpaceNew(); // Create new Space
space->gravity = cpv(0, -100); // Direcction and magnitude of gravity in Space
[NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(delta:) userInfo:nil repeats:YES]; // NSTimer for animations
// Create esfera Body
cpBody *esferaBody = cpBodyNew(50.0f, INFINITY);
esferaBody->p = cpv(160,250);
// Create esfera Shape
cpShape *esferaShape = cpCircleShapeNew(esferaBody, 15.0f, cpvzero);
esferaShape->e = 0.5f; // Elasticity
esferaShape->u = 0.8f; // Friction
esferaShape->data = esfera; // UIImageView association
esferaShape->collision_type = 1;
cpSpaceAddBody(space, esferaBody);
cpSpaceAddShape(space, esferaShape);
}
- (void) delta:(NSTimer *)timer {
cpSpaceStep(space, 1.0f/60.0f); // Refresh Space info
cpSpaceHashEach(space->activeShapes, &updateShape, nil); // Refresh Shapes info
}
void updateShape(void *ptr, void *unused) {
cpShape *shape = (cpShape*)ptr;
if (shape == nil || shape->body == nil || shape->data == nil) {
NSLog(@"Invalid Shape...");
return;
}
// Refresh Shape position
if ([(UIView*)shape->data isKindOfClass:[UIView class]]) {
[(UIView*)shape->data setCenter:CGPointMake(shape->body->p.x, 480 - shape->body->p.y)];
} else {
NSLog(@"Shape updated outside updateShape function...");
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
barra = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"barra.png"]];
barra.center = CGPointMake(160, 350);
esfera = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"esfera.png"]];
esfera.center = CGPointMake(160, 230);
[self.view addSubview:barra];
[self.view addSubview:esfera];
[self.view setBackgroundColor:[UIColor whiteColor]];
[self configurarChipmunk];
}
...
@end
答
您应该使用iphonestatic.command脚本的MacOSX的/目录下建一个静态库并像README说的那样为你复制标题。然后你所要做的就是把这个文件夹放到你的项目中。
如果您只是将源代码复制到项目中,那么几乎肯定会丢失几个非常重要的优化标志。不要这样做!
答
我从cocos2d +花栗鼠模板复制花栗鼠文件夹结构,并构建好。
* Classes/Chipmunk/include/src for 'src' folder
* Classes/Chipmunk/chipmunk for 'include' folder
答
我有同样的问题,这天,我这样做:
1.-转到项目 - >内添加到项目,并找到了cocos2d-iphone-0.99.5文件,然后从目录我已经添加了External目录(包含花栗鼠文件)。确保在将项目复制到目标组文件夹(如果需要)旁边的复选框中有复选标记,然后单击添加按钮。
2:我按照这个教程:http://monoclestudios.com/cocos2d_whitepaper.html(在页面的中间是所有的信息需要补充花栗鼠)
3.-更改的#include“限制/ util.h”声明: “#include util.h”
我想完成了。
你使用什么命令来编译和链接? – Beta 2010-08-18 17:48:44
命令?我做CMD + B来构建应用程序,我可以在哪里找到xcode执行编译和链接的确切命令? – rubdottocom 2010-08-18 17:57:27
我解决了这个问题,谢谢 – rubdottocom 2010-08-18 18:14:49