0
\$\begingroup\$

I am trying to build my project in VS, which is a copy of HelloWorld.cpp provided by Bullet. I am getting a list of errors of sort "unresolved external symbol" when I build my project, however everything is alright with HelloWorld.cpp.

What I did prior to the event: I have downloaded Bullet from repository, started build_visual_studio_vr_pybullet_double.bat as suggested in the guide, which produced .sln file. I opened the file and built BulletDynamics, BulletCollision and LinearMath. Then I added Bullet source folder into my project include directories, as well as generated .lib files for all 3 project to my project additional dependencies (via Project->Properties).

What I did to solve the problem:

  1. Set Runtime Library = /MT in properties both for my project and bullet (tried various values, but similar on both sides)
  2. Built Bullet projects following specific order: Duynamics->Collision->LinearMath Notjing worked out. Please help!

Source.cpp code for my project applied:

#include "btBulletDynamicsCommon.h"
#include <stdio.h>

/// This is a Hello World program for running a basic Bullet physics simulation

int main()
{
///-----includes_end-----

int i;
///-----initialization_start-----

///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();

///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);

///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();

///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);

dynamicsWorld->setGravity(btVector3(0, -10, 0));

///-----initialization_end-----

//keep track of the shapes, we release memory at exit.
//make sure to re-use collision shapes among rigid bodies whenever possible!
btAlignedObjectArray<btCollisionShape*> collisionShapes;

///create a few basic rigid bodies

//the ground is a cube of side 100 at position y = -56.
//the sphere will hit it at y = -6, with center at -5
{
    btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.)));

    collisionShapes.push_back(groundShape);

    btTransform groundTransform;
    groundTransform.setIdentity();
    groundTransform.setOrigin(btVector3(0, -56, 0));

    btScalar mass(0.);

    //rigidbody is dynamic if and only if mass is non zero, otherwise static
    bool isDynamic = (mass != 0.f);

    btVector3 localInertia(0, 0, 0);
    if (isDynamic)
        groundShape->calculateLocalInertia(mass, localInertia);

    //using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects
    btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
    btRigidBody* body = new btRigidBody(rbInfo);

    //add the body to the dynamics world
    dynamicsWorld->addRigidBody(body);
}

{
    //create a dynamic rigidbody

    //btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
    btCollisionShape* colShape = new btSphereShape(btScalar(1.));
    collisionShapes.push_back(colShape);

    /// Create Dynamic Objects
    btTransform startTransform;
    startTransform.setIdentity();

    btScalar mass(1.f);

    //rigidbody is dynamic if and only if mass is non zero, otherwise static
    bool isDynamic = (mass != 0.f);

    btVector3 localInertia(0, 0, 0);
    if (isDynamic)
        colShape->calculateLocalInertia(mass, localInertia);

    startTransform.setOrigin(btVector3(2, 10, 0));

    //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colShape, localInertia);
    btRigidBody* body = new btRigidBody(rbInfo);

    dynamicsWorld->addRigidBody(body);
}

/// Do some simulation

///-----stepsimulation_start-----
for (i = 0; i < 150; i++)
{
    dynamicsWorld->stepSimulation(1.f / 60.f, 10);

    //print positions of all objects
    for (int j = dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--)
    {
        btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j];
        btRigidBody* body = btRigidBody::upcast(obj);
        btTransform trans;
        if (body && body->getMotionState())
        {
            body->getMotionState()->getWorldTransform(trans);
        }
        else
        {
            trans = obj->getWorldTransform();
        }
        printf("world pos object %d = %f,%f,%f\n", j, float(trans.getOrigin().getX()), float(trans.getOrigin().getY()), float(trans.getOrigin().getZ()));
    }
}
system("pause");
///-----stepsimulation_end-----

//cleanup in the reverse order of creation/initialization

///-----cleanup_start-----

//remove the rigidbodies from the dynamics world and delete them
for (i = dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
{
    btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];
    btRigidBody* body = btRigidBody::upcast(obj);
    if (body && body->getMotionState())
    {
        delete body->getMotionState();
    }
    dynamicsWorld->removeCollisionObject(obj);
    delete obj;
}

//delete collision shapes
for (int j = 0; j < collisionShapes.size(); j++)
{
    btCollisionShape* shape = collisionShapes[j];
    collisionShapes[j] = 0;
    delete shape;
}

//delete dynamics world
delete dynamicsWorld;

//delete solver
delete solver;

//delete broadphase
delete overlappingPairCache;

//delete dispatcher
delete dispatcher;

delete collisionConfiguration;

//next line is optional: it will be cleared by the destructor when the array goes out of scope
collisionShapes.clear();
}
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Your question doesn't provide enough information. In most cases you should check where each error comes from (which function), and resolve the linking errors, as they appear.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .