getting Bullet running, even as simple as hello world

Post Reply
elbasofolous
Posts: 4
Joined: Sat Oct 25, 2008 5:25 pm
Location: Midwest USA

getting Bullet running, even as simple as hello world

Post by elbasofolous »

hello,
I would really like to get Bullet working on my own. I am using xcode in leopard and was able to compile the demos with no problem using cmake, but this makes it difficult for me to move beyond that. My eventual goal is to get Bullet to feed position and rotation values into the irrlicht engine, but for now i simply want to be able to compile the hello world cpp file in a project by itself.

i see that after compiling the xcodeproject made by cmake that there is the following list of .a libraries:

libLibBulletColladaConverter.a, libLibGIMPACT.a, libLibBulletCollision.a, libLibGIMPACTUtils.a, libLibBulletDynamics.a, libLibGLUI.a, libLibBulletMultiThreaded.a, libLibLinearMath.a, libLibBulletSoftBody.a, libLibOpenGLSupport.a, libLibColladaDom.a, libLibXML.a, libLibConvexDecomposition.a

so my first question is, are these all that I should need? for instance, the manual references libbulletmath -> is this the same as libLibBulletLinearMath?

my next question is how i get just hello world to compile (or any of the other demos for that matter) once ive added these libs to the project and also created a group for the src/ directory

any help in this regard would be greatly appreciated
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: getting Bullet running, even as simple as hello world

Post by Erwin Coumans »

To compile Bullet/Demos/HelloWorld, you need to #include the Bullet/src folder

Link against libBulletDynamics, libBulletCollision, libLinearMath (or libBulletMath, ignore the libLib prefix, it is a cmake build issue).

Or even easier: just recursively add all .cpp files from Bullet/src/BulletCollision, Bullet/src/BulletDynamics and Bullet/src/LinearMath directly to your project.
Hope this helps,
Erwin
elbasofolous
Posts: 4
Joined: Sat Oct 25, 2008 5:25 pm
Location: Midwest USA

Re: getting Bullet running, even as simple as hello world

Post by elbasofolous »

first off, thankyou for the speedy reply, I never expected such an immediate response, and from the creator no less :-)

I wanted to not be too hasty in replying to be sure that I'd exhausted all my options first, but I'm still having the same issues.
I think that the linked lib files are in perfect working order but that perhaps xcode is to blame?
most of my errors are claiming that a lot of the .h files aren't there. I add the /src folder to the project, and tell it to recursively add groups to the project, and this is verified by resulting hierarchical group in the project. I also tried stripping the src directory of everything but the .h files and then added the folders and files to the project's directory so that theyd to be relative to btBulletDynamicsCommon.h on the filesystem and still am getting the same errors
HelloWorld.cpp is definately seeing btBulletDynamicsCommon.h, but btBulletDynamicsCommon.h isnt seeing its dependencies
my hello world currently is:

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

int main(int argc, char** argv)
{
/* code */
}

...just to be certain the errors are resulting from btBulletDynamicsCommon

I can attach the project, or a file containting the error output if need be (3xxx or so errors) but I'd really like to nail down the source of my problem

Im just wondering what magic it is that cmake provides that allows for not only the libraries to compile, but then the demos afterwards and to make it look so effortless
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: getting Bullet running, even as simple as hello world

Post by chunky »

Assuming you're actually going to be building a new xcode project for your new Hello World application rather than use one provided by Bullet, here's what I do in my projects [keep in mind that this may read really long, but it's a thirty second task when you actually do it]:

First, copy Bullet's src dir into a subdir of your project. May as well do this so you can statically link in XCode more easily. Switching from debug to release builds includes switching your xcode-managed libraries [such as Bullet]. Keep a copy of Bullet in your SCM like this and you'll save yourself a lot of effort. Additionally, this means that you can add include search paths relative the project file, and it won't matter where check it out to [for example, if you're collaborating with someone who checks out to their home dir, while you checkout to a "src" subdirectory].

Next, in your xcode project, [assuming you've created one, which you must have in order to get to the hello world bit you described above], go to project->new target. Click on "BSD" in the left hand pane, and then "Static Library" in the right hand pane.

Give it a name like "twbullet" [I have the "tw" prefix on all targets in my project to avoid potential linktime conflicts with system-wide libraries]. Click finish. You'll notice that there's now a "libtwbullet.a" file in your file listing for the project, although right now it'll be red which means it's not yet built.

Now go to your filesystem in finder, find the whole Bullet source directory, and drag it onto XCode. When you go back to xcode, you'll find it's offering you a panel of which targets to add those files to. Uncheck your main target, and check your Bullet target instead. Now XCode will manage the building of your Bullet library.

Finally, right click on your main application target, and click "Get Info". Go to the left hand tab marked "General", and then click add to add the other target to your application's dependencies. Also click the other add button to add the output library from the bullet target, to your target.

Now XCode will magically do all management of your Bullet library. It'll build it when it needs it, and [my favorite], switching from release to debug builds will build release or debug flavors of the library, as well as of your main application.

Finally, if you need to fix the include paths, right click on your application target and click "Get Info" again. Go to the "build" tab, make sure you have "all configurations" selected, and grep for "header search". Double click on header search paths, and add your top level bullet source directory from your project.

If I have time and someone bumps this thread tomorrow to remind me, I'll try to put those instructions on the wiki and provide screenshoterrific happy fun time with it.

Gary (-;
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: getting Bullet running, even as simple as hello world

Post by chunky »

Im just wondering what magic it is that cmake provides that allows for not only the libraries to compile, but then the demos afterwards and to make it look so effortless
Of course, on non-OSX systems, I use CMake. Same setup as I use for XCode [obviously], with bullet as a subdir of my main project.
In the bullet source dir, I have this CMakeLists.txt:

Code: Select all

INCLUDE_DIRECTORIES(
        .
        BulletCollision/BroadphaseCollision
        BulletCollision/CollisionDispatch
        BulletCollision/CollisionShapes
        BulletCollision/NarrowPhaseCollision
        BulletDynamics/ConstraintSolver
        BulletDynamics/Dynamics
        BulletDynamics/Vehicle
        BulletSoftBody/
        LinearMath
)

FILE(GLOB BULLET_SRCGLOB
        BulletCollision/BroadphaseCollision/*.cpp
        BulletCollision/CollisionDispatch/*.cpp
        BulletCollision/CollisionShapes/*.cpp
        BulletCollision/NarrowPhaseCollision/*.cpp
        BulletDynamics/ConstraintSolver/*.cpp
        BulletDynamics/Dynamics/*.cpp
        BulletDynamics/Vehicle/*.cpp
        BulletSoftBody/*.cpp
        LinearMath/*.cpp
)

ADD_LIBRARY(twbullet STATIC ${BULLET_SRCGLOB})
Then my top level CMakeLists.txt file looks something like this:

Code: Select all

CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
PROJECT(HelloWorld)
INCLUDE_DIRECTORIES(src/bullet) # Add bullet to the user include dir

SUBDIRS(src/bullet/) # This line will read in the CMakeLists.txt for Bullet

FILE(GLOB ALL_SRCGLOB src/*.cpp) # all .cpp files in src/

ADD_EXECUTABLE(HelloWorld ALL_SRCGLOB) # Add all those source files to HelloWorld
TARGET_LINK_LIBRARIES(HelloWorld twbullet)
Obviously that's not really what I use, but that's sufficient magic to build and link with Bullet, via CMake starting from scratch.

Gary (-;
elbasofolous
Posts: 4
Joined: Sat Oct 25, 2008 5:25 pm
Location: Midwest USA

Re: getting Bullet running, even as simple as hello world

Post by elbasofolous »

ok, as far as i can tell, this step is what makes or breaks it, and right now if i create a project to only build the library i get 10015 or so errors
Now go to your filesystem in finder, find the whole Bullet source directory, and drag it onto XCode. When you go back to xcode, you'll find it's offering you a panel of which targets to add those files to. Uncheck your main target, and check your Bullet target instead. Now XCode will manage the building of your Bullet library.
when setting up the project, i create an empty project, add a bsd static library target then, as quoted, add the src/ directory to the project.
on the add dialog:
i leave copy contents unchecked as src/ is already in the project dir
reference type: default / text: utf8
check recursively create groups
check the bsd static lib target i created

so, my first question is, are any of these settings incorrect and is there any prep you do on bullet-2.72/src to make it work?
second, if i have the bullet libs from the cmade xcode project for the demos, can i just include those instead of rebuilding the library(s) in the current project? (as recommended by Erwin)
if so, how do i make xcode see src files that are clearly there, relative to helloworld.cpp both on the filesystem and in groups in xcode?

as mentioned, im using bullet 2.72 and my xcode version should be the most recent, 3.1.1

i feel like this shouldnt be this difficult and at the same time, have tried every combination i can think of and still have yet to compile even an empty main() that includes btBulletDynamicsCommon.h (or anything bullet related for that matter: static lib file, helloworld, etc)

(just as an aside to where im coming from - for the irrlicht engine, I create an empty proj, add carbon, appkit, opengl and cocoa frameworks, add the libirrlicht.a compiled in irrlicht's demo/source and add all of these under link binary with library for a carbon application target. then i add a reference to just irrlicht.h from the include directory, no matter where on the fs is it, and compile my same code from windows and linux, as well as any of the simple cpp's from /examples with no issues)
it seems like this same approach should work, and be even more straightforward for an app that only writes to the console, but im just not getting it :-(
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: getting Bullet running, even as simple as hello world

Post by chunky »

Mh. Sounds like perhaps the includes aren't being found - are the errors near the top indicative of that?

If that's the case, right click on the Bullet target in the targets list, and click "Get Info". Go down to "Header Search Paths", and add the Bullet source dir to it. This dir is relative to the xcode project. For example:

Code: Select all

proj/
proj/MyProj.xcodeproj
proj/src/
proj/src/hello.cpp
proj/src/bullet/
proj/src/bullet/btBulletDynamicsCommon.h
You would need to add "./src/bullet/" to the user include paths. You'll need to add it to the user include paths for Bullet, and for your project that uses it.

It's worth noting that you can just set Bullet as your active target with project->set active target->{your Bullet target}, and clicking build will just build that. Presumably you want to make sure that's working before attempting to build your other app using it.

Gary (-;
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: getting Bullet running, even as simple as hello world

Post by Erwin Coumans »

Please follow the instructions here, it includes screenshots for setting up a XCode project from scratch:

http://www.bulletphysics.com/mediawiki- ... om_scratch

Hope this helps,
Erwin
elbasofolous
Posts: 4
Joined: Sat Oct 25, 2008 5:25 pm
Location: Midwest USA

Re: getting Bullet running, even as simple as hello world

Post by elbasofolous »

thanks so much Erwin and Gary,
I appreciate you guys replying so quickly, Im think Im all good to go now
Post Reply