在chipmunk中运行名为bounce.c的演示时出错

发布于 2024-08-28 21:20:07 字数 5100 浏览 6 评论 0原文

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#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; i<steps; i++)
    {
        cpSpaceStep(space, dt);
    }
}

static void
add_box()
{
    const cpFloat size = 10.0f;
    const cpFloat mass = 1.0f;

    cpVect verts[] = {
        cpv(-size,-size),
        cpv(-size, size),
        cpv( size, size),
        cpv( size,-size),
    };

    cpFloat radius = cpvlength(cpv(size, size));

    cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForPoly(mass, 4, verts, cpvzero)));
    body->p = 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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#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; i<steps; i++)
    {
        cpSpaceStep(space, dt);
    }
}

static void
add_box()
{
    const cpFloat size = 10.0f;
    const cpFloat mass = 1.0f;

    cpVect verts[] = {
        cpv(-size,-size),
        cpv(-size, size),
        cpv( size, size),
        cpv( size,-size),
    };

    cpFloat radius = cpvlength(cpv(size, size));

    cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForPoly(mass, 4, verts, cpvzero)));
    body->p = 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,
};

This is the code . The error i get when i run it is .

 /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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2024-09-04 21:20:07

您需要更新标头搜索路径。

You need to update your header search path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文