2010-08-18 143 views
1

[求助]如何將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 
+1

你使用什麼命令來編譯和鏈接? – Beta 2010-08-18 17:48:44

+0

命令?我做CMD + B來構建應用程序,我可以在哪裏找到xcode執行編譯和鏈接的確切命令? – rubdottocom 2010-08-18 17:57:27

+0

我解決了這個問題,謝謝 – rubdottocom 2010-08-18 18:14:49

回答

4

您應該使用iphonestatic.command腳本的MacOSX的/目錄下建一個靜態庫並像README說的那樣爲你複製標題。然後你所要做的就是把這個文件夾放到你的項目中。

如果您只是將源代碼複製到項目中,那麼幾乎肯定會丟失幾個非常重要的優化標誌。不要這樣做!

0

我從cocos2d +花栗鼠模板複製花栗鼠文件夾結構,並構建好。

* Classes/Chipmunk/include/src for 'src' folder 
* Classes/Chipmunk/chipmunk for 'include' folder 
0

我有同樣的問題,這天,我這樣做:

1.-轉到項目 - >內添加到項目,並找到了cocos2d-iphone-0.99.5文件,然後從目錄我已經添加了External目錄(包含花栗鼠文件)。確保在將項目複製到目標組文件夾(如果需要)旁邊的複選框中有複選標記,然後單擊添加按鈕。

2:我按照這個教程:http://monoclestudios.com/cocos2d_whitepaper.html(在頁面的中間是所有的信息需要補充花栗鼠)

3.-更改的#include「限制/ util.h」聲明: 「#include util.h」

我想完成了。

0

如果您使用的CocoaPods:

  1. 在Xcode中點擊你的項目
  2. 選擇花栗鼠物理目標
  3. 搜索路徑設置總是搜索用戶路徑
  4. i ñ頭搜索路徑設置

「$ {PODS_ROOT} /頭/個人/花栗鼠物理學」 到遞歸

「$ {PODS_ROOT} /頭/公/花栗鼠物理學」到遞歸

xcode screenshot

希望它可以幫助別人

相關問題