一千萬個為什麽

搜索

在chipmunk中運行一個名為bounce.c的演示時出錯

#include 
#include 
#include 

#include "/home/satyajit/Chipmunk-5.2.0/include/chipmunk/chipmunk.h"
#include "drawSpace.h"
#include "ChipmunkDemo.h"

cpSpace *space;
cpBody *staticBody;

int i;
static void
update(int ticks)
{
    int steps = 3;
    cpFloat dt = 1.0f/60.0f/(cpFloat)steps;

    for( i=0; ip = cpv(frand()*(640 - 2*radius) - (320 - radius), frand()*(480 - 2*radius) - (240 - radius));
    body->v = cpvmult(cpv(2*frand() - 1, 2*frand() - 1), 200);

    cpShape *shape = cpSpaceAddShape(space, cpPolyShapeNew(body, 4, verts, cpvzero));
    shape->e = 1.0f; shape->u = 0.0f;
}

static cpSpace *
init(void)
{
    staticBody = cpBodyNew(INFINITY, INFINITY);

    cpResetShapeIdCounter();

    space = cpSpaceNew();
    cpSpaceResizeActiveHash(space, 30.0f, 1000);
    space->iterations = 10;

    cpShape *shape;

   //Create segments around the edge of the screen.
    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,240), cpv(320,240), 0.0f));
    shape->e = 1.0f; shape->u = 1.0f;
    shape->layers = NOT_GRABABLE_MASK;

    for(i=0; i<10; i++)
        add_box();

    cpBody *body = cpSpaceAddBody(space, cpBodyNew(100.0f, 10000.0f));

    shape = cpSpaceAddShape(space, cpSegmentShapeNew(body, cpv(-75,0), cpv(75,0), 5.0f));
    shape->e = 1.0f; shape->u = 1.0f;

    cpSpaceAddConstraint(space, cpPivotJointNew2(body, staticBody, cpvzero, cpvzero));

    return space;
}

static void
destroy(void)
{
    cpBodyFree(staticBody);
    cpSpaceFreeChildren(space);
    cpSpaceFree(space);
}

const chipmunkDemo Bounce = {
    "Bounce",
    NULL,
    init,
    update,
    destroy,
};

這是代碼。我運行它時得到的錯誤是。

 /usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o: In function `_start':
    (.text+0x18): undefined reference to `main'
    /tmp/ccyG1FXX.o: In function `update':
    Bounce.c:(.text+0x37): undefined reference to `cpSpaceStep'
    /tmp/ccyG1FXX.o: In function `add_box':
    Bounce.c:(.text+0x18f): undefined reference to `cpvlength'
    Bounce.c:(.text+0x1d3): undefined reference to `cpMomentForPoly'
    Bounce.c:(.text+0x1e2): undefined reference to `cpBodyNew'
    Bounce.c:(.text+0x1f4): undefined reference to `cpSpaceAddBody'
    Bounce.c:(.text+0x368): undefined reference to `cpPolyShapeNew'
    Bounce.c:(.text+0x37a): undefined reference to `cpSpaceAddShape'
    /tmp/ccyG1FXX.o: In function `init':
    Bounce.c:(.text+0x45c): undefined reference to `cpBodyNew'
    Bounce.c:(.text+0x466): undefined reference to `cpResetShapeIdCounter'
    Bounce.c:(.text+0x46b): undefined reference to `cpSpaceNew'
    Bounce.c:(.text+0x48f): undefined reference to `cpSpaceResizeActiveHash'
    Bounce.c:(.text+0x548): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x55a): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x610): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x622): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x6cf): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x6e1): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x78e): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x7a0): undefined reference to `cpSpaceAddStaticShape'
    Bounce.c:(.text+0x7fd): undefined reference to `cpBodyNew'
    Bounce.c:(.text+0x80f): undefined reference to `cpSpaceAddBody'
    Bounce.c:(.text+0x89b): undefined reference to `cpSegmentShapeNew'
    Bounce.c:(.text+0x8ad): undefined reference to `cpSpaceAddShape'
    Bounce.c:(.text+0x91d): undefined reference to `cpPivotJointNew2'
    Bounce.c:(.text+0x92f): undefined reference to `cpSpaceAddConstraint'
    /tmp/ccyG1FXX.o: In function `destroy':
    Bounce.c:(.text+0x949): undefined reference to `cpBodyFree'
    Bounce.c:(.text+0x956): undefined reference to `cpSpaceFreeChildren'
    Bounce.c:(.text+0x963): undefined reference to `cpSpaceFree'
    collect2: ld returned 1 exit status

最佳答案

您需要更新標題搜索路徑。

轉載註明原文: 在chipmunk中運行一個名為bounce.c的演示時出錯