Getting started [problems with Hello World]

radio
Posts: 5
Joined: Sun Mar 14, 2010 3:10 pm

Getting started [problems with Hello World]

Post by radio »

Hi all

Im just trying to compile "Hello World" example from wiki and I have such problems:

Code: Select all

#include <btBulletDynamicsCommon.h>
#include <iostream>
 
int main () {
    std::cout << "Hello World!" << std::endl;
 
    // Build the broadphase
    btBroadphaseInterface* broadphase = new btDbvtBroadphase();
 
    // Set up the collision configuration and dispatcher
    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
 
    // The actual physics solver
    btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
 
    // The world.
    btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
    dynamicsWorld->setGravity(btVector3(0,-10,0));
 
    // Do_everything_else_here
 
 
    // Clean up behind ourselves like good little programmers
    delete dynamicsWorld;
    delete solver;
    delete dispatcher;
    delete collisionConfiguration;
    delete broadphase;
 
    return 0;
}
This code above ends without any errors during compilation, but i get segmentation fault at line:

Code: Select all

 btBroadphaseInterface* broadphase = new btDbvtBroadphase(); 
And I have no idea what's wrong.


I tried using another source code from wiki

Code: Select all

#include <iostream>
 
#include <btBulletDynamicsCommon.h>
 
int main (void)
{
 
        btBroadphaseInterface* broadphase = new btDbvtBroadphase();
 
        btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
        btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
 
        btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
 
        btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
 
        dynamicsWorld->setGravity(btVector3(0,-10,0));
 
 
        btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
 
        btCollisionShape* fallShape = new btSphereShape(1);
 
 
        btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
        btRigidBody::btRigidBodyConstructionInfo
                groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
        btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
        dynamicsWorld->addRigidBody(groundRigidBody);
 
 
        btDefaultMotionState* fallMotionState =
                new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
        btScalar mass = 1;
        btVector3 fallInertia(0,0,0);
        fallShape->calculateLocalInertia(mass,fallInertia);
        btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
        btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
        dynamicsWorld->addRigidBody(fallRigidBody);
 
 
        for (int i=0 ; i<300 ; i++) {
                dynamicsWorld->stepSimulation(1/60.f,10);
 
                btTransform trans;
                fallRigidBody->getMotionState()->getWorldTransform(trans);
 
                std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;
        }
 
        dynamicsWorld->removeRigidBody(fallRigidBody);
        delete fallRigidBody->getMotionState();
        delete fallRigidBody;
 
        dynamicsWorld->removeRigidBody(groundRigidBody);
        delete groundRigidBody->getMotionState();
        delete groundRigidBody;
 
 
        delete fallShape;
 
        delete groundShape;
 
 
        delete dynamicsWorld;
        delete solver;
        delete collisionConfiguration;
        delete dispatcher;
        delete broadphase;
 
        return 0;
}
At this time i cannot compile it (i get errors with one of the functions).

I'm using Ubuntu 9.10.
I have to idea if those problems are connected with my OS or wrong (?) installation of this library ;/

Anyone have and idea what's wrong ?
krux
Posts: 11
Joined: Tue Apr 06, 2010 7:25 pm

Re: Getting started [problems with Hello World]

Post by krux »

please post error messages
radio
Posts: 5
Joined: Sun Mar 14, 2010 3:10 pm

Re: Getting started [problems with Hello World]

Post by radio »

With first code i just get "normal" segmentation fault

Code: Select all

przemo@przemo-laptop:~/Pulpit/Roboty Mobilne$ ./prog 
Hello World!
Segmentation fault
przemo@przemo-laptop:~/Pulpit/Roboty Mobilne$ 
And with the second code (during compilation) i get:

Code: Select all

przemo@przemo-laptop:~/Pulpit/Roboty Mobilne$ make
g++ proba.cpp -o prog -Wall -pedantic -l BulletDynamics -l BulletCollision -l BulletSoftBody -l BulletMultiThreaded -l OpenGLSupport -l LinearMath  
/tmp/ccvp7s1K.o: In function `main':
proba.cpp:(.text+0x262): undefined reference to `btStaticPlaneShape::btStaticPlaneShape(btVector3 const&, float)'
collect2: ld returned 1 exit status
make: *** [prog] Błąd 1
przemo@przemo-laptop:~/Pulpit/Roboty Mobilne$ 
My Makefile:

Code: Select all

BIBLIOTEKA=-l BulletDynamics -l BulletCollision -l BulletSoftBody -l BulletMultiThreaded -l OpenGLSupport -l LinearMath  
prog: proba.cpp
        g++ proba.cpp -o prog  -Wall -pedantic $(BIBLIOTEKA)

clean:
        @rm -r *.o -f

krux
Posts: 11
Joined: Tue Apr 06, 2010 7:25 pm

Re: Getting started [problems with Hello World]

Post by krux »

sorry can't help, I have Ubuntu, too and I had my own problems, but now it works.
radio
Posts: 5
Joined: Sun Mar 14, 2010 3:10 pm

Re: Getting started [problems with Hello World]

Post by radio »

Np. I totally understand you :P

Most irritating is fact that those programs are taken from Bullet wiki, and still i cannot run them to start working with this library ;/
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Getting started [problems with Hello World]

Post by Erwin Coumans »

The order of linking libraries is important:

Code: Select all

-l BulletMultiThreaded -l BulletSoftBody -l BulletDynamics -l BulletCollision -l LinearMath
hope this helps,
Erwin
radio
Posts: 5
Joined: Sun Mar 14, 2010 3:10 pm

Re: Getting started [problems with Hello World]

Post by radio »

@Erwin Coumans

Still same problems ;/

I would never thought that order in which i link libraries can have any importance .....